Vue repeated routing error problem

When the Vue route is clicked repeatedly, an error Uncaught (in promise ) NavigationDuplicated: Avoided redundant navigation to current location: XXX will appear  . Although it does not affect the running results, it is best to deal with it.
insert image description here

local treatment

Local processing refers to processing a single route, while other routes still report errors.

在路由跳转的push语句中添加catch捕捉错误

So the original routing jump is changed to the following code:

		toecharts(){
            this.$router.push({
                    path:'/echarts'
                }
            ).catch(err => {})		//添加catch捕捉错误
        }

global processing

Global processing refers to the processing of all routes.

在main.js文件添加以下代码(代码直接复制就好,无需改动)

import Router from 'vue-router'

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

Guess you like

Origin blog.csdn.net/Qhx20040819/article/details/132642585