-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Cancel navigateBack from canDeactivate #528
Comments
Just wondering if this has any attention. It is causing me a bit of grief. |
@TonyLugg Thanks for your detailed report. Running gist here: https://gist.run/?id=f4a7fa39c9d82f5de0af3b0bc8e01850 |
Hello! Any update on this bug? |
I'm going to want to start looking at this for 1.6.0, potentially a March release if all goes well. |
The core issue is that |
I'm not familiar with the implementation details but wouldn't it be logical to call history.back only after candeactivate returns true? It seems weird to me that we navigate back before checking if we are allowed to. |
It's not a straightforward switch. I've done some experiments calling |
I've found a number of related bugs. Specifically, if you start at Some early tests show this solving this issue and most of the related issues I've uncovered:
I need to do additional testing to with pushState and with child routers. |
This strategy is not a good one because it enters an infinite loop when the user navigates back (or forwards) more than one entry. I think the only and right way to handle this is using sessionStorage. I'm going to give that a try. |
It has been a year since I reported this issue. Any update on expected fix date? |
I did spend a fair amount of time trying to fix it, but unfortunately due to limitations on the browser detailed above I was not able to make sufficient progress. I'd be happy to accept a PR from a community member who thinks they may have a solution. |
Thanks for the update. We will avoid using CanDeactivate. |
I'd really like to see it too. I'd be happy to work with you on it. It's tougher than it seems. If you open up a preliminary PR we can collaborate on it as well. |
I'll take a look later this weekend. Just to be clear (since I haven't really used the "exit" cycle steps): canDeactivate only triggers when you're navigating (either through link or history) to a different page within the same Aurelia application, right? Since navigation is done via browser location, if I go from |
Preventing a navigation with canDeactivate doesn't cancel the browser history navigation. This fix moves the browser back to the index where navigation was cancelled. Depending on PR aurelia/history-browser#42. Closes aurelia#528.
Note that this doesn't in any way prevent a user from leaving the Aurelia application; it only deals with navigation within the application. |
I'm happy to help with testing. However, I am a .NET/WPF with TFS guy turned Aurelia, so the whole git workflow is a bit foreign to me. If you can help me setup the test environment I will make the effort. |
Thanks @TonyLugg! I've made two extra branches to simplify testing so just installing
in a project should do. |
OK, I will give this a try. Are they ready now? |
Yeah, should be. |
@gama410 This is on me. I was asked to create some thorough tests for this and have so far been coming up short. I hope to have it fixed before the end of the week. |
Ok great! Thanks for your work! |
It works in the basic case but edge cases are not handled, e.g. when a route is not found. See here for the status of the PR: #621 |
Is there any viable workaround for this issue? I need to ask user about leaving the large form with unsaved data. |
So the bug is that there is no way to cancel "back" when you click it. You might try |
You mean something like this?
Thanks, I can give it a try. Otherwise, I guess I need to ensure I return true from |
Hmm... I found that
Doing so will not update window title where it should be, but otherwise seems to be working. |
I'm submitting a bug report
Library Version:
aurelia-router: 1.3.0
Operating System:
Windows 10
Node Version:
6.11.3
NPM Version:
5.3.0
JSPM OR Webpack AND Version
Webpack 3.5.5 (using CLI)
Browser:
all
Language:
TypeScript 2.5.2
Current behavior:
I load the app, which loads "home" route/view. Press a button and use router.navigate("second") to go to second page. Enter some data and press back button (on page) which executes router.navigateBack(). Because data has changed, display a message box (Aurelia dialog) from canDeactivate() to ask for user confirmation (same behavior with window.confirm()), and return false from canDeactivate(). Navigation stops. Repeat from pressing back button (on page), backward navigation continues and navigates right out of the app as if it has navigated back twice.
https://gist.github.com/TonyLugg/f4a7fa39c9d82f5de0af3b0bc8e01850
Expected/desired behavior:
Each time false is returned from canDeactivate, navigateBack() should be stopped.
If I press a different button and perform navigate("someOtherRoute") and return false from canDeactivate it works correctly with multiple navigation attempts.
The text was updated successfully, but these errors were encountered: