父级上的 Vue Router 可选参数不会渲染子级

发布于 2025-01-11 16:31:01 字数 613 浏览 2 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文