-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw Error "NavigationDuplicated" #2872
Comments
This is expected, it's part of the new promise api: before, if no callbacks were supplied to The behavior with 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 |
Hi @posva is there a plan to fix this also ? |
there are two versions of push and replace matching what actually happens |
pushing a new URL (that is the same path as current page) but the search/hash makes the URL different, doesn't work anymore. |
@shmaram I will give it a try and push a fix during the day, thanks for letting me know! |
It's fixed now, I will publish a version during the day |
@posva Why does it throw a NavigationDuplicated error when updating params, though? For instance, the router page might be named "User" and have |
the navigation failure should only happen if the final location is the same as the current one. If it happens with different params, it's a bug so please open a new issue with a boiled down repro |
I can confirm this behavior using E.g., replacing this.$router.replace({
path: '/search',
query: {
term: 'lorem',
sort: 'alphabetical'
}
}) will cause the 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 |
Is there a shorter way the prevent the console warning than |
@posva and what about redirecting inside a route guard?
Is this even possible? Because I'm getting this error caused by a route guard :( |
@Aferz the catch must be attached to the push/replace methods |
Is this fixed? |
AFAIK the problem didn't appear when I tried. As with any other bug, a boiled reproduction is required. So please open a new issue with it if you can reproduce it. One possibility for the error to happen is to have another push somewhere else or Locking this one to redirect to that 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.
<router-link>
does not have the same behavior. There is no error even if you're pushing the current page.The text was updated successfully, but these errors were encountered: