参数后面使用 ?
id 后面加个 ‘ ? ’ ,将 id 设置为可选参数
{
name: "index",
path: '/p/:id?',
component: resolve =>void(require(['../components/admin/layout/index.vue'], resolve))
}
// ==
{ path: '/p/:id?', name: 'index', component: Index}
成长路上的一些知识分享,如有错误,欢迎指正批评!O(∩_∩)O
本文介绍了一种在路由配置中设置可选参数的方法,通过在参数后面添加问号(?),可以使该参数变为非必填项。此技巧适用于前端路由配置,例如在Vue Router中定义路径时使用。
281

被折叠的 条评论
为什么被折叠?



