【问题标题】:Vue router appends url to current urlVue路由器将url附加到当前url
【发布时间】:2020-12-09 13:10:15
【问题描述】:

我正在使用 vue 2。我已经注册了路由。两条路线是membershipsmemberships/:id

当我使用时:

this.$router.push({ path: 'memberships'} );

在此之后任何this.$router.push 都会导致追加到

http://localhost:8000/memberships/bronze
http://localhost:8000/memberships/silver

http://localhost:8000/memberships/shop 代替http://localhost:8000/shop

http://localhost:8000/memberships/deals 代替http://localhost:8000/deals

【问题讨论】:

    标签: javascript vue.js vuejs2 path vue-router


    【解决方案1】:

    在所有基本路由路径中使用前导斜杠:

    this.$router.push({ path: '/memberships' });
    

    在基本路由定义中也这样做。您也可以命名您的路线并按名称推送:

    this.$router.push({ name: 'memberships'} );
    

    【讨论】:

      猜你喜欢
      • 2021-12-17
      • 2017-02-07
      • 1970-01-01
      • 2019-06-22
      • 2018-11-10
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      • 2019-08-26
      相关资源
      最近更新 更多