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.

Make `NavigationDuplicated` a no-op for `push` and `replace`

See original GitHub issue

What 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 of vue-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 attached catch 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:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

68reactions
dominik-blncommented, Oct 11, 2019

So maybe this is a case that could benefit from configuration:

const router = new Router({
    routes: [],
    mode: 'history',
   // other options could be: 'reload', 'throw' and default to `throw` to avoid breaking changes
    duplicateNavigationPolicy: 'ignore'
})
4reactions
posvacommented, Apr 29, 2020
Read more comments on GitHub >

github_iconTop 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 >

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