Vue路由中重定向和别名有何本质区别?

2026-04-03 01:200阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计969个文字,预计阅读时间需要4分钟。

Vue路由中重定向和别名有何本质区别?

重定向+重定向也是通过+routers+配置完成的,下面例子是从+/a+重定向到+/b+:+const+router+=+ new+ VueRouter({+routes:+[+{+path:+’+/a+’,+redirect:+’+/b+’+}+]});+重定向的目标也可以是一个命名的路由:+const+route+

Vue路由中重定向和别名有何本质区别?

重定向

重定向也是通过 routes 配置来完成,下面例子是从 /a 重定向到 /b:

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

重定向的目标也可以是一个命名的路由:

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

甚至是一个方法,动态返回重定向目标:

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

注意导航守卫并没有应用在跳转路由上,而仅仅应用在其目标上。

阅读全文

本文共计969个文字,预计阅读时间需要4分钟。

Vue路由中重定向和别名有何本质区别?

重定向+重定向也是通过+routers+配置完成的,下面例子是从+/a+重定向到+/b+:+const+router+=+ new+ VueRouter({+routes:+[+{+path:+’+/a+’,+redirect:+’+/b+’+}+]});+重定向的目标也可以是一个命名的路由:+const+route+

Vue路由中重定向和别名有何本质区别?

重定向

重定向也是通过 routes 配置来完成,下面例子是从 /a 重定向到 /b:

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

重定向的目标也可以是一个命名的路由:

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

甚至是一个方法,动态返回重定向目标:

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

注意导航守卫并没有应用在跳转路由上,而仅仅应用在其目标上。

阅读全文