vue 路由相同路徑跳轉報錯


在進行vue商城項目 同頁跳同頁 參數改變時 報錯

//本頁路由
  /inmall?id=46
//跳轉
  /inmall?id=30
//方法
   goinne(id) {
                this.$router.push({path: `/inmall`, query: {id: id}})
            },
 // 報錯

vue-router.esm.js?fe87:2051 Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated", message: "Navigating to current location ("/inmall?id=36") is not allowed", stack: "Error↵ at new NavigationDuplicated (webpack-int…node_modules/vue/dist/vue.runtime.esm.js:1853:26)"}

解決方法
  • 重寫路由的push方法
  • 解決,相同路由跳轉時,報錯
           const originalPush = Router.prototype.push;
           Router.prototype.push = function push(location, onResolve, onReject) {
             if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
             return originalPush.call(this, location).catch((err) => err);
           };

在router.js中添加就好了

      const originalPush = Router.prototype.push
      Router.prototype.push = function push(location) {
        return originalPush.call(this, location).catch(err => err)
      }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM