vue - 对于相同路径的跳转,不要在控制台中报错 Avoided redundant navigation to current location

访问量: 11

参考: https://stackoverflow.com/questions/62462276/how-to-solve-avoided-redundant-navigation-to-current-location-error-in-vue

代码:

import VueRouter from 'vue-router'

/**
 * 对于相同路径的跳转,不要在console中报错.
 */
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => {
    if (
      err.name !== 'NavigationDuplicated' &&
      !err.message.includes('Avoided redundant navigation to current location')
    ) { 
      logError(err);
    }   
  })  
}

/* eslint-disable no-new */
new Vue({
  components: { App },
  router,
  store,
  template: ''
}).$mount('#app')

订阅/RSS Feed

Subscribe

分类/category