当我尝试创建一个以数组作为参数的 router-link
时,该链接有效,但收到以下警告:
missing param for named route "start-run": Expected "files" to not repeat, but received
["aaa"]
router.js
...
{
path: '/start-run/:config?/:files?',
name: 'start-run',
component: StartRun,
props: true
},
...
文件.vue
...
<router-link :to="{name: 'start-run', params: { config: 'test', files: ['aaa'] }}">...</router-link>
...
我没有找到解决此警告的文档。
最佳答案
我相信错误消息来自 Vue Router 使用的 path-to-regexp
版本 1.7.0:
https://github.com/pillarjs/path-to-regexp/blob/v1.7.0/index.js#L185
问题是数组被视为多个值,但路径中的参数不支持多个值。
目前尚不清楚您试图通过将数组传递给文件
来实现什么目的。您定义的路由路径使用 :files?
的 ?
后缀,这使得它是可选的,但不允许使用数组。也许您的意思是 :files*
或 :files+
?或者也许您只想传递数组中的第一项?
关于javascript - 路由参数中的数组导致 "Expected to not repeat"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58714652/