I have problem related to vue-router I need to exclude some group of words like: word1, some-word2, word3... from the router path
{
path: '/:pageIdenfifier(?!word1|some-word2|word3),
name: 'SomePage',
component: () => import('@/views/index'),
props: true,
}
but it doesn't work - https://paths.esm.dev/?p=AAMeJbiAwBIUTHbAdgHNgAGvAjgHhxDgd4DsAYC1AEYGfCB1eFujBYAiq5kBdgSY4KMICgAA&t=/word1#
As alternative, you can use beforeEnter guard for this route, like:
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();
}
}
]
})
In beforeEnter just check if pageIdenfifier match some value from blackList, in case of true you should provide another route or 404 page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With