question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Throw Error "NavigationDuplicated"

See original GitHub issue

Version

3.1.1

Reproduction link

https://codesandbox.io/s/vue-template-i2d63

Steps to reproduce

Use $router.push to change the “page”. If you are using the same page, vue-router throw an Error.

What is expected?

Just nothing, or a warning.

What is actually happening?

An Error has been thrown.


  • To my point of view it’s not an error. On a previous version of ‘vue-router’ no error was threw: https://codesandbox.io/s/vue-template-qvrfr
  • <router-link> does not have the same behavior. There is no error even if you’re pushing the current page.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

27reactions
posvacommented, Aug 7, 2019

This is expected, it’s part of the new promise api: before, if no callbacks were supplied to router.push, errors were only sent to the global router error handler. Now, because they return a promise, if the error is not caught, you will see a warning in the console. But the error was always there because trying to navigate to same location as the current one will fail

The behavior with router-link is consistent with how it was working before, no errors are emitted (except globally), it’s catching the error by adding a noop callback:

router.push('/location', () => {})

However, the correct solution if you don’t care about errors is catching the error:

router.push('/location').catch(err => {})

The last version makes more sense as the Promise api is likely to become the default and the callback version to become deprecated

25reactions
imtblcommented, Aug 18, 2019

@posva Why does it throw a NavigationDuplicated error when updating params, though? For instance, the router page might be named “User” and have params: { id: userId }. If you call this.$router.push({ name: 'User', params: { id: selectedUserId }}) to change the user being rendered for the current page, should that really count as a NavigationDuplicated error? This is the way it is recommended to change the data for a page, so it seems odd that getting an error is expected behavior.

I can confirm this behavior using this.$router.replace(). Just replacing the query params will cause the NavigationDuplicated error.

E.g., replacing #/search?term=lorem&sort=relevance with #/search?term=lorem&sort=alphabetical via

 this.$router.replace({
  path: '/search',
  query: {
    term: 'lorem',
    sort: 'alphabetical'
  }
})

will cause the NavigationDuplicated error if not catching via

 this.$router.replace({
  path: '/search',
  query: {
    term: 'lorem',
    sort: 'alphabetical'
  }
}).catch(err => {})

It will correctly update the current URL regardless of catching the error or not though.

Is this.$router.replace() not intended to be used for this? I didn’t see any other function in the docs for just replacing the query params.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NavigationDuplicated Navigating to current location ("/search ...
I only wanted to silence NavigationDuplicated error, an empty catch can be dangerous. So I did this : const router = new VueRouter({/*...
Read more >
How to fix NavigationDuplicated Vue Router error
“NavigationDuplicated” is one such error being thrown explicitly when the user clicks <router-link> or ( router.push() / router.replace() called ...
Read more >
Handling "NavigationDuplicated" error - Get Help - Vue Forum
Hello there! In the newest versions of vue-router we got an error if we go to the same location (screenshot: http://prntscr.com/p130n1).
Read more >
Got Uncaught (in promise) NavigationDuplicated error on ...
Hello, In laravel 5 / vuejs 2.6 app I have login form and on login failure I got error : Copy Code app.js?dt=1571914585:131483...
Read more >
How to fix 'Avoided redundant navigation to current location ...
You can solve it by using the catch clause: ... 'NavigationDuplicated' && !error.message.includes('Avoided redundant navigation to current ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found