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

feature request: pass navigationInstruction to canDeactivate #493

Closed
MattGiesa opened this issue May 1, 2017 · 8 comments
Closed

feature request: pass navigationInstruction to canDeactivate #493

MattGiesa opened this issue May 1, 2017 · 8 comments

Comments

@MattGiesa
Copy link

I'm submitting a feature request

  • Library Version:
    1.3.0

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Browser:
    all

  • Language:
    TypeScript 2.3

Current behavior:
No arguments are passed to canDeactivate, so the requested route cannot be used to determine actions needed to be taken.

Expected/desired behavior:

  • What is the expected behavior?
    Pass the navigationInstruction to canDeactivate so that the requested route can be inspected before taking action.

  • What is the motivation / use case for changing the behavior?
    I want to confirm navigation only if the user requested a route outside of the current parent route. If the user navigates to a sibling route, I want to allow navigation without confirming. The scenario is a wizard, where the user can navigate between pages of the wizard before saving, but shouldn't be able to leave the wizard altogether.
    This can be achieved by handling canDeactivate on the parent, but NOT if the activation strategy is "replace" or "invoke-lifecycle", because then canDeactivate is called on the parent when navigating between children too.

@MattGiesa
Copy link
Author

If the request is accepted I would be happy to work on this

@EisenbergEffect
Copy link
Contributor

By all means, please proceed :) Have a look in activation.js for the place to make the change. Thanks!

@MattGiesa
Copy link
Author

So I tried simply passing the navigationInstruction into the call to canDeactivate as you can see here but at this point in the pipeline calling getAllInstructions() on this navigationInstruction doesn't return all instructions, it only ever returns one even when there are two child routers.

Next I tried moving LoadRouteStep in front of CanDeactivateStep in the PipelineProvider (here), and now I get exactly what I need in canDeactivate - three navigationInstructions when there are two child routers.

I think LoadRouteStep ends up loading the actual components too though, right? If that's the case this isn't the right approach, and I'm not sure where to go next.

Can I get some guidance on this please?

@MattGiesa
Copy link
Author

What editor/extensions do you guys use to build this? VS Code whines that "types can only be used in .ts files", and I'm not sure what I need to install to get support for the type declarations.
Thanks

@EisenbergEffect
Copy link
Contributor

We're not using any editor extensions. Technically, these are Flow types supported by Babel. We're planning to move this all to TS.

Regarding the questions above, we don't want to change the order of the steps.

@MattGiesa
Copy link
Author

We don't need this enhancement anymore. Please feel free to close the feature request if no one else is asking for it.

Thanks

@mttmccb
Copy link

mttmccb commented Jul 15, 2017

This would be useful, the alternative seems a bit hacky... Will look at a PR.

@mttmccb
Copy link

mttmccb commented Jul 18, 2017

Made a start, not quite sure where to go from here but passing the navigationInstruction to the processing function seems like a good start. https://github.com/mttmccb/router

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

3 participants