Skip to content
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

canDeactivate() only fired once when using navigation buttons (back/forward) #731

Open
Krossmaskinen opened this issue Mar 2, 2017 · 2 comments

Comments

@Krossmaskinen
Copy link

I'm submitting a bug report

  • Library Version:
    1.1.0

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    6.9.4

  • NPM Version:
    4.1.2
  • JSPM OR Webpack AND Version
    JSPM 0.16.52
  • Browser:
    Chrome 56.0.2924.87
    Firefox 51.0.1 (32 bit)

  • Language:
    TypeScript 2.1.5

Current behavior:

  • If canDeactivate() returns false it doesn't fire again when using the navigation buttons, back and forward.
  • The navigation history in the browser changes, you can see the navigation buttons get disabled and enabled when you reach the edges of the history object, when using the navigation buttons, however the route inside the aurelia app doesn't change. If you came from a different site and navigate back enough times the browser will navigate to that site as it normally would.
  • canDeactivate() does fire again if you reload the page, click a link, or enter a url in the browser.
  • If choosing "ok" the navigation happens and the canDeactivate() fires again the next time you come back to the page and try to navigate again.

Expected/desired behavior:
canDeactivate() should fire every time you try to navigate away from a page. In this example the confirm popup should show every time I hit back or forward.

  1. Add the following to a view model class:
    canDeactivate() { return confirm('you wanna leave?'); // if you hit 'cancel' here, canDeactivate() won't fire again when using navigation buttons }
  2. Navigate to the route
  3. Try navigating away from it using any method
  4. Select "cancel" in the confirm popup
  5. Try to navigate again using back or forward in the browser or on the mouse
  6. canDeactivate() is now skipped. Aurelia navigation is disabled but browser navigation occurs.

Can't reproduce in gist because it involves navigation using back and forward.

  • What is the motivation / use case for changing the behavior?
    I make a check for unsaved data in a form and prompt the users if they really want to leave if there are any. If they hit "cancel" they should be prompted again if they try to navigate away again until they either save the data or click "ok" in the prompt.
@dmytro-y-dev
Copy link

Any update on this?

@janat08
Copy link

janat08 commented Dec 6, 2018

Is being fixed by aurelia/router#621

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants