Search code examples
vue.jsnuxt.jsvue-routerrouter

Vue router path - How use regex to check if URL path contain a substring?


Hi I am trying add path string matching on the path url on the root level.

If the path will check if it contains "/br_", if matched, it will use a specified component for the route.

routes.push({
   {
       name: 'company-search-results',
       path: '/(\\/br_)',
       component: resolve(__dirname, 'pages/company-search-results/-index'),
   },
});

But it is not picking up, what did I do wrong?


Solution

  • The NUXT/vue route is using path-to-regex modules, so I have to go through their documentation and evenually I found the solution as below:

    path: '/*/:brand(.*br_.*)'