2

I have this route /test/a-vs-b

I am trying to catch this route only if -vs- is found in it.

I tried a few regex variants, but nothing seems to work

routes.push({
    name: 'test',
    path: '/test/:page((.*)-vs-(.*))',
    component: resolve(__dirname, 'test/b.vue'),
});

Any ideas?

Patrioticcow
  • 26,422
  • 75
  • 217
  • 337
  • I think the answers to my questions can clarify few things: https://stackoverflow.com/questions/59035905/nuxt-encode-decode-uri-with-double-colon – Billal Begueradj Dec 15 '19 at 15:04

1 Answers1

4

VueRouter uses the path-to-regexp library, which apparently doesn't handle defining capturing groups with parenthesis like you're trying to do.


I got it to work by simply removing the parenthesis surrounding the .*s.

routes.push({
    name: 'test',
    path: '/test/:page(.*-vs-.*)',
    component: resolve(__dirname, 'test/b.vue'),
});
thanksd
  • 54,176
  • 22
  • 157
  • 150