美文网首页
router路由配置

router路由配置

作者: 饥人谷_米弥轮 | 来源:发表于2017-08-29 02:35 被阅读13次
  • alias 为路由别名,当在地址栏的文件路径输入路由别名时,将跳转到对应的文件路径,但不会文件路径的名字不会改变
    • 注意:虽然通过路由别名可以访问到对应的文件路径,但是因为router-link设置的地址是'/home',所以触发不了对应的css
image.png image.png
  • redirect为重定向,可以设置为字符串和对象、函数,当设置函数时可以动态指定重定向目标
export default new Router({
  mode: 'history',
  linkActiveClass: 'is-active',
  routes: [
    {
      path: '/home',
      name: 'home',
      component: home,
      alias: '/index'
    }
    {
      path: '*',
      // component: notfound
      // redirect: '/home'
      // redirect: {path: '/about'}
      // redirect: {name: 'document'}
      redirect: (to) => { //动态设置重定向的目标
        // 目标路由对象
        // console.log(to)
        if(to.path === '/123'){
          return '/home'
        }else if(to.path === '/456'){
          return {path: '/about'}
        }else{
          return {name: 'document'}
        }
      }
    }
  ]
})

相关文章

网友评论

      本文标题:router路由配置

      本文链接:https://www.haomeiwen.com/subject/hdbndxtx.html