【问题标题】:Children components routing wont change to proper url子组件路由不会更改为正确的 url
【发布时间】:2021-05-20 07:51:28
【问题描述】:

我正在尝试为我的设置页面设​​置路由器链接,每当我点击帐户时,它会将我定向到 localhost/account 而不是 localhost/settings/account 我已经为设置页面提供了孩子,为什么会发生这种情况?

Settings.vue

   router-link(to="/")
          button(class='hover:text-blue-500 focus:outline-none')
            | Profile
        router-link(:to="{name: 'Account'}")
          button(class='hover:text-blue-500 focus:outline-none')
            | Account
      router-view
 {
        path: "/settings",
        name: "Settings",
        component: Settings,
        children: [{
            path: "",
            name: "Profile",
            component: Profile
          },
          {
            path: "/account",
            name: "Account",
            component: Account
          }
        ]
      },

【问题讨论】:

    标签: vue.js vuejs2 vue-router


    【解决方案1】:

    删除帐户路径的前导斜杠。前导斜杠表示它是从根开始的路由。

    {
            path: "/settings",
            name: "Settings",
            component: Settings,
            children: [{
                path: "",
                name: "Profile",
                component: Profile
              },
              {
                path: "account", // now it works as intended
                name: "Account",
                component: Account
              }
            ]
          },
    

    【讨论】:

    • 谢谢,你知道为什么每次切换菜单项时我的两个项目都是active 类吗?
    • 您的意思是“个人资料”和“帐户”这两个项目?您可能需要使用完全匹配:router.vuejs.org/api/#exact
    猜你喜欢
    • 2017-02-03
    • 2018-08-06
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 2023-01-20
    • 2021-01-13
    • 2018-04-18
    • 1970-01-01
    相关资源
    最近更新 更多