Vue:Navigating to current location ("") is not allowed

最近更新时间 2019-12-29 23:45:35

Navigating to current location ("") is not allowed

点击当前菜单时报上面错误信息。不能切换到当前路由。

解决方案:

src/router/index.js文件里面添加下面的代码即可解决。

import Router from 'vue-router'

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

添加上面代码后,效果为点击当前页面路由后页面不刷新,没有反应,不会报错。

rss_feed