vue的router学习笔记3之路由重定向和别名

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40283784/article/details/87287471

1.路由重定向

const router = new VueRouter({
  routes: [
    { path: '/a', redirect: to => {
      // 方法接收 目标路由 作为参数
      // return 重定向的 字符串路径/路径对象
    }}
  ]
})
const router = new VueRouter({
  routes: [
    { path: '/a', redirect: { name: 'foo' }}
  ]
})

当访问/a的时候,/a的路径将被替换成/b,也就是说,访问的/a被重定向成了/b。

2.路由别名

const router = new VueRouter({
  routes: [
    { path: '/a', component: A, alias: '/b' }
  ]
})

当访问/a时,url是/b,但是路由目标依旧是/a。

猜你喜欢

转载自blog.csdn.net/qq_40283784/article/details/87287471