vuejs2 - 我可以在 Vue 的路由器中为特定路由设置多个别名吗?
问题描述
事情是这样的,虽然 alias 现在完美地满足了我的需求,但我想知道如何为路径声明多个别名,那么,这样的事情会起作用吗?例子:
export default new Router({
routes: [
{
path: '/',
name: 'home',
component: Home,
alias: ['/home', '/home2', '/homeN']
},
{
path: '/about',
name: 'about',
component: () => import('./views/About.vue')
}
]
})
我的意思是,这是推荐的方法吗?Vue路由器中是否有更好的做法?
解决方案
这很好,他们甚至有一个官方的例子。
const router = new VueRouter({
mode: 'history',
base: __dirname,
routes: [
{ path: '/root', component: Root, alias: '/root-alias' },
{ path: '/home', component: Home,
children: [
// absolute alias
{ path: 'foo', component: Foo, alias: '/foo' },
// relative alias (alias to /home/bar-alias)
{ path: 'bar', component: Bar, alias: 'bar-alias' },
// multiple aliases
{ path: 'baz', component: Baz, alias: ['/baz', 'baz-alias'] },
// default child route with empty string as alias.
{ path: 'default', component: Default, alias: '' },
// nested alias
{ path: 'nested', component: Nested, alias: 'nested-alias',
children: [
{ path: 'foo', component: NestedFoo }
]
}
]
}
]
});
如果您更担心拼写错误,那么您可能只在*
通配符路径上使用导航防护,该路径基于路由路径的子字符串进行重定向。
推荐阅读
- css - 两列四项
- ruby-on-rails - html_safe doesn't work when I call truncate() method
- linux - 403 Forbidden 您无权访问此服务器上的/www/cgibin/webadmin.cgi
- c# - 最佳实践:自定义 asp.net core 身份授权
- rest - Amazon S3 DELETE 请求成功但未返回确认?
- amazon-web-services - 从实例中检索特定标签的值
- java - 将对象值列表转换为组
- javascript - 手动显示工具提示 Chart.js
- asp.net-mvc - Log4Net 未使用 UnityContainer 登录 .NET WebApi 项目
- php - GF2 代码的高斯消除