javascript - 路由参数中的数组导致“预期不会重复”警告
问题描述
当我尝试router-link
使用数组作为参数创建一个时,链接有效,但我收到以下警告:
命名路由“start-run”的缺少参数:预期的“文件”不会重复,但已收到
["aaa"]
路由器.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>
...
我没有找到解决此警告的文档。
解决方案
我相信错误消息来自path-to-regexp
Vue Router 使用的 1.7.0 版本:
https://github.com/pillarjs/path-to-regexp/blob/v1.7.0/index.js#L185
问题是数组被视为多个值,但路径中的参数不支持多个值。
目前尚不清楚通过将数组传递给files
. 您定义的路由路径使用?
后缀 for :files?
,这使其成为可选但不允许使用数组。也许你的意思是:files*
或者:files+
相反?或者,也许您只想传递数组中的第一项?
推荐阅读
- python - 在 IDLE shell 中输入多行/语句?
- sql - WHERE IN () 中的 SQL SELECT 语句
- ruby-on-rails - Rails Action 文本、pdf 和视频预览未在 Chrome 和 Firefox 中显示
- php - 显示来自刚刚在 PHP 中注册的用户 ID 的消息
- uwp - 标准 Windows 11 图标,包括 UWP 应用中的颜色
- react-hook-form - react-hook-form:验证对象的工作原理
- google-apps-script - Google Apps 脚本 - google 表单中的线性比例
- php - 如何从 array_map 的 array_map 获取属性?
- visual-studio - vcxprj 文件可以定义为
- reactjs - Dockerized Create React App 不会打开新选项卡