javascript - 如何使用正则表达式匹配nuxtjs,vue中路由中的特定单词?
问题描述
我有这条路线/test/a-vs-b
只有在其中找到这条路线时,我才试图抓住这条路线-vs-
。
我尝试了一些正则表达式变体,但似乎没有任何效果
routes.push({
name: 'test',
path: '/test/:page((.*)-vs-(.*))',
component: resolve(__dirname, 'test/b.vue'),
});
有任何想法吗?
解决方案
VueRouter 使用该path-to-regexp
库,它显然不能像您尝试做的那样处理用括号定义捕获组。
我通过简单地删除围绕.*
s 的括号来使其工作。
routes.push({
name: 'test',
path: '/test/:page(.*-vs-.*)',
component: resolve(__dirname, 'test/b.vue'),
});
推荐阅读
- process - 操作系统中进程运行状态和执行状态的区别
- hive - Athena 的 .csv.metadata 文件的数据格式是什么?
- stm32 - 在 stm32H7 上运行 YOLOv3-tiny 怎么样?
- ruby - RubyMine 在尝试创建 SDK 时出现通信错误
- javascript - 如何通过 SocketIO 使用 CommonJS 导出和导入?
- c# - 如何从动态代码中使用的特定节点访问子节点?
- laravel - 不显示搜索结果
- coredump - exec查询cmd时的Greenplum coredump
- python - 查找使用列表表示的所有组合
- java - 如何修复“org.hibernate.boot.registry.selector.spi.StrategySelectionException:无法解析名称 [org.hibernate.dialect.MySQL8Dialect]”?