router路由配置

2017-08-29  本文已影响13人  饥人谷_米弥轮
image.png image.png
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'}
        }
      }
    }
  ]
})
上一篇 下一篇

猜你喜欢

热点阅读