close

[Solved] NavigationDuplicated Navigating to current location (“/search”) is not allowed

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error NavigationDuplicated Navigating to current location (“/search”) is not allowed in vuejs. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How To Solve NavigationDuplicated Navigating to current location (“/search”) is not allowed Error ?

  1. How To Solve NavigationDuplicated Navigating to current location (“/search”) is not allowed Error?

    To Solve NavigationDuplicated Navigating to current location (“/search”) is not allowed Error in order to solve the issue you can compare the router navigation with the current route and only navigate if they differ.

  2. NavigationDuplicated Navigating to current location (“/search”) is not allowed

    To Solve NavigationDuplicated Navigating to current location (“/search”) is not allowed Error in order to solve the issue you can compare the router navigation with the current route and only navigate if they differ.

Solution 1

in order to solve the issue you can compare the router navigation with the current route and only navigate if they differ:

const path = `/products/${id}`
if (this.$route.path !== path) this.$router.push(path)

Solution 2

I think the best solution to this can be solved at the root label if we are not going to use further Router.push as asynchronous call.

import Router from 'vue-router';

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

Vue.use(Router);

Solution 3

If you are not feeling comfortable catching all kind of errors, I think this implementation is more considerate:

this.$router.push("path").catch(error => {
  if (error.name != "NavigationDuplicated") {
    throw error;
  }
});

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment