-
-
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
Make NavigationDuplicated
a no-op for push
and replace
#2963
Comments
I'm happy to bring the conversation but I would like to see new points brought to the table. I did my best in explaining it at #2881 (comment) and will gladly add more precisions. Regarding your points:
I'm still open to suggestions and I do search things myself like always resolving and never rejecting but allowing users to detect errors by using For 3.x no changes are going to happen unless they are non-breaking, but I look forward to make things convenient and flexible for 4.x I will open an issue to track and organize the discussion of should push reject or not and possible improvements about navigation failure |
Thank you for your quick reply.
Interesting, I was totally convinced that this would just do nothing and not reload. I think the main opinion difference I, and probably other commenters had as well, is the way in which I'd personally only reject for errors where it's absolutely certain that the client code must handle them (you could probably call this this.$router.push({ name: 'some-route'}).then((route) => {
if (route.path === this.$route.path) {
throw new Error('Navigation Duplicated')
}
// do the actual then processing
}).catch((error) => { console.error(error) }) I just remembered that the Apollo GraphQL client has a setting to switch between these approaches: https://www.apollographql.com/docs/react/v2.5/api/react-apollo/#optionserrorpolicy |
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'
}) |
There are three sort of concrete use cases of router.push and router.replace (while allowing genuine errors to bubble up):
If the router allows push to succeed for a duplicate location, this is just:
If the router allows push to succeed for a duplicate location, this:
If the router allows push to succed for a duplicate location, this is just:
I think use case 1 is probably the most common, but in all use cases but the racey operation, the code is cleaner allowing push to return the successful promise but the level of dirtiness of the racey operation is lower with manual deduplication then the messiness for the other use cases with the enforced deduplication. When performing a racey operation, the developer probably is most aware of the sensitivity of the operation and will want to guard that anyways. Then again, acquiring locks isn't that obvious to a lot of people. I would avoid calling this navigation. The method is called push and people have intuitive ideas of what it means to navigate somewhere (you are already there being successful), but a push that doesn't modify the (navigation) stack has failed, so I am sympathetic to returning a failed promise for a push that doesn't actually modify the navigation stack. With replace it is harder to argue that this should fail, I can always redundantly replace an object with itself. So one solution would be to add methods like I am in use case 1 all the time, so I think I am going to be replacing router.push with a function that redundantly succeeds:
|
I believe @dominik-bln suggestion of an ignore flag would be most beneficial. Having to add a no-op catch to every single one of my $router.push/replace calls on the off chance they might link to the active page is madness. |
I came here as a newbie looking for why I got this error while already being on the page and the button got clicked again. Reading it all, I do think @dominik-bln suggestion of having an option for this would be great. In that case it's up to the consumer to decide what happens and it avoids having to add My use case: Thank you for having another look at this. |
vuejs/rfcs#150 addresses this 🙂 |
Landing here as I'm trying to find a solution to the While Essentially, we would like to get rid of the trailing slash (without a user error) in the URL. |
What problem does this feature solve?
Since a recent change every call to
push
orreplace
that is handed the same path as is currently active is rejecting with aNavigationDuplicated
error and clients that don't care about this duplication need to attach a no-opcatch
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:<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.push
without an attachedcatch
because otherwise we might get irrelevant error logs, i. e. the API is now always (albeit minimally) more complex.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.
The text was updated successfully, but these errors were encountered: