我有与vue-路由器相关的问题,我需要从路由器路径中排除一些单词,比如:word1、some-word2、word3.
{
path: '/:pageIdenfifier(?!word1|some-word2|word3),
name: 'SomePage',
component: () => import('@/views/index'),
props: true,
}发布于 2021-09-03 13:34:36
作为替代,您可以在此路由中使用beforeEnter保护,例如:
const blackList = ['word1','some-word2','word3']
const router = new VueRouter({
routes: [
{
path: '/:pageIdenfifier',
name: 'SomePage',
component: () => import('@/views/index'),
props: true,
beforeEnter: (to, from, next) => {
blackList.includes(to.params.pageIdenfifier)
? next('/route-in-case-of-true')
: next();
}
}
]
})在beforeEnter中,只需检查pageIdenfifier是否与来自blackList的值匹配,如果是true,则应提供另一条路由或404页。
https://stackoverflow.com/questions/69045529
复制相似问题