Throw Error "NavigationDuplicated"
See original GitHub issueVersion
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:
- Created 4 years ago
- Comments:15 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 failThe 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:However, the correct solution if you don’t care about errors is catching the error:
The last version makes more sense as the Promise api is likely to become the default and the callback version to become deprecated
I can confirm this behavior using
this.$router.replace()
. Just replacing the query params will cause theNavigationDuplicated
error.E.g., replacing
#/search?term=lorem&sort=relevance
with#/search?term=lorem&sort=alphabetical
viawill cause the
NavigationDuplicated
error if not catching viaIt 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.