如何使用正则表达式来匹配nuxtjs中的特定单词,vue?

问题描述 投票:1回答:1

我有这条路线/test/a-vs-b

我试图抓住这条路线只有在其中找到-vs-

我尝试了一些正则表达式变体,但似乎没有任何效果

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

有任何想法吗?

javascript vue.js routes nuxt.js
1个回答
2
投票

VueRouter使用path-to-regexp库,apparently doesn't handle defining capturing groups with parenthesis就像你想要做的那样。


我通过简单地删除围绕.*s的括号来实现它。

routes.push({
    name: 'test',
    path: '/test/:page(.*-vs-.*)',
    component: resolve(__dirname, 'test/b.vue'),
});
© www.soinside.com 2019 - 2024. All rights reserved.