Categories
Vue Answers

How to fix the ‘Avoided redundant navigation to current location’ error in Vue.js?

Spread the love

Sometimes, we want to fix the ‘Avoided redundant navigation to current location’ error in Vue.js.

In this article, we’ll look at how to fix the ‘Avoided redundant navigation to current location’ error in Vue.js.

How to fix the ‘Avoided redundant navigation to current location’ error in Vue.js?

To fix the ‘Avoided redundant navigation to current location’ error in Vue.js, we can call $router.push only if the route isn’t the same as the current route.

For instance, we write

if (this.$route.path !== "/dashboard") {
  this.$router.push("/dashboard");
}

to check if the current route isn’t /dashboard with

this.$route.path !== "/dashboard"

If it’s true, then we go to /dashboard with

this.$router.push("/dashboard");

Conclusion

To fix the ‘Avoided redundant navigation to current location’ error in Vue.js, we can call $router.push only if the route isn’t the same as the current route.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *