Patrioticcow
Patrioticcow

Reputation: 27058

How to use regex to match specific words in a route in nuxtjs, vue?

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?

Upvotes: 2

Views: 3971

Answers (1)

thanksd
thanksd

Reputation: 55664

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'),
});

Upvotes: 4

Related Questions