父级上的 Vue Router 可选参数不会渲染子级
我的 vue 路由器 (v4.0.13) 中有以下设置:
const routes = [
{
path: "/:lang(en|fr)?",
component: Layout, //Top-level component that contains the basic elements (sidebar, header, footer).
children: [
{
path: "",
name: "Home",
component: Home,
},
{
path: "other",
name: "Other",
component: Other,
},
],
},
];
布局、主页、其他是我的组件。问题是以下路由不会渲染 Home 组件:
/
或 /en
。
如果我删除 ?
并将参数设置为非可选,则 /en
会正确渲染 Home 组件,但 /
路由不再起作用。
我缺少什么?
I have the following setup in my vue router (v4.0.13):
const routes = [
{
path: "/:lang(en|fr)?",
component: Layout, //Top-level component that contains the basic elements (sidebar, header, footer).
children: [
{
path: "",
name: "Home",
component: Home,
},
{
path: "other",
name: "Other",
component: Other,
},
],
},
];
with Layout, Home, Other being my components. The problem is that the following routes don't render the Home component:
/
or /en
.
If I remove the ?
and make the parameter non optional then /en
renders the Home component correctly but the /
route doesn't work anymore.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论