【问题标题】:Using an absolute path in a vue-router route在 vue-router 路由中使用绝对路径
【发布时间】:2020-03-27 13:00:37
【问题描述】:

在我的 Vue 应用程序中,我有以下路线(以及其他路线)

  {
    path: '/event/:eventId?',
    name: 'event',
    component: EventTask
  },
  {
    path: '/terms-and-conditions',
    name: 'terms-and-conditions',
    component: TermsAndConditions
  }

条款和条件的链接显示在页脚中,因此可以从任何页面访问。如果我在活动路线上,我点击条款和条件的链接

<router-link to="terms-and-conditions">
  <v-btn text>Terms of Use</v-btn>
</router-link>

浏览器导航到路径/event/terms-and-conditions,而不是/terms-and-conditions。我怎样才能使它成为一条绝对路线,所以它总是导航到/terms-and-conditions

【问题讨论】:

    标签: vue.js vue-router


    【解决方案1】:

    您可以指定路线的名称

    <router-link :to="{ name: 'terms-and-condition' }">
       <v-btn text>Terms of Use</v-btn>
    <router-link>
    

    https://router.vuejs.org/api/#to

    【讨论】:

      猜你喜欢
      • 2022-11-30
      • 1970-01-01
      • 1970-01-01
      • 2018-02-17
      • 1970-01-01
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      相关资源
      最近更新 更多