Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem related to vue-router, i can not exclude some words from path regex

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#

like image 598
Evgen Matiola Avatar asked Feb 02 '26 19:02

Evgen Matiola


1 Answers

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

like image 177
Vasile Radeanu Avatar answered Feb 05 '26 08:02

Vasile Radeanu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!