Make `NavigationDuplicated` a no-op for `push` and `replace`
See original GitHub issueWhat problem does this feature solve?
Since a recent change every call to push
or replace
that is handed the same path as is currently active is rejecting with a NavigationDuplicated
error and clients that don’t care about this duplication need to attach a no-op catch
clause to all calls. I am aware that there was already a discussion on this topic in #2872 and can understand the viewpoints expressed by the maintainers there. However I’d still like to ask to reconsider this change and not reject for duplicated navigations.
The main arguments I would put into consideration against treating NavigationDuplicated
as an error are:
- Not rejecting is more consistent with how
<a>
tags and<router-link>
are working, i. e. I’d argue it is the API that is least surprising to users ofvue-router
because it is how browsers usually work. - A client can already find out if a duplication is happening by looking at the current route and the push target if this functionality is desired. While this might be slightly more complicated for that use-case, the changed API puts a burden on all clients that don’t care about the duplication, which is IMHO the more common case.
- It essentially seems not possible anymore to call
push
without an attachedcatch
because otherwise we might get irrelevant error logs, i. e. the API is now always (albeit minimally) more complex. - Introducing the rejection was effectively a breaking change of the API for a lot of clients. The observable behaviour of pushing the same navigation twice was a no-op before and now it isn’t anymore.
What does the proposed API look like?
A duplicated navigation is a “no-op” or warning log in vue-router itself and doesn’t require clients to handle this in any way.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Navigation Duplicated when pushing new query to vue-router
So besides pushing to my variable I was mutating the original array from this.$route.query in background without thinking about it.
Read more >Navigationduplicated Navigating To Current Location ...
Make `NavigationDuplicated` a no-op for `push` and `replace` hot 31. and the console throws a NavigationDuplicated error, Programmer Sought, ...
Read more >https://faring.com/private/js/app.js?version=6abe4...
Make sure to call `Vue.use(VueRouter)` before creating root instance."),this.apps.push(e),e.$once("hook:destroyed",(function(){var t=r.apps.
Read more >Avoided redundant navigation to - OSCHINA - 中文开源技术 ...
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to ... location).catch(err => err) } ``` replace同理,将代码push更改为了replace即可.
Read more >https://one57.com/private/js/app.js?version=ee0183
{ns}/g,""),o[i]=n[i].replace(/{ns}/g,t)));return o}function n(){f. ... ResizeHandlers.push({namespace:n,priority:r.priority,callback:r.methods._resize}),f.
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
So maybe this is a case that could benefit from configuration:
https://github.com/vuejs/rfcs/pull/150 addresses this 🙂