Error as shown in figure:

Problem description: When repeatedly clicking the navigation, the console appears an error, although it does not affect the use of functions, but also can not ignore.

Solution:

Solution 1: Use the catch method to catch router-push exceptions

This.$router.push(route).catch(err => {console.log(' error ',err)})Copy the code

Solution 2: Check whether the forward route is consistent with the current route to avoid repeated hops.

toMenu (item) { if (this.$route.path ! == item.url) { this.$router.push({ path: item.url }) } }Copy the code

Solution 3: Just add the following code to the router folder:

// src/router/index.js Vue.use(Router) const router = new Router({ routes }) const VueRouterPush = Router.prototype.push  Router.prototype.push = function push (to) { return VueRouterPush.call(this, to).catch(err => err) }Copy the code