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

Comments

Projects
None yet
3 participants
@MattGiesa

MattGiesa commented May 1, 2017

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

This comment has been minimized.

Show comment
Hide comment
@MattGiesa

MattGiesa May 1, 2017

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

MattGiesa commented May 1, 2017

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

@EisenbergEffect

This comment has been minimized.

Show comment
Hide comment
@EisenbergEffect

EisenbergEffect May 2, 2017

Member

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

Member

EisenbergEffect commented May 2, 2017

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

@MattGiesa

This comment has been minimized.

Show comment
Hide comment
@MattGiesa

MattGiesa May 7, 2017

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 commented May 7, 2017

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

This comment has been minimized.

Show comment
Hide comment
@MattGiesa

MattGiesa May 7, 2017

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

MattGiesa commented May 7, 2017

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

This comment has been minimized.

Show comment
Hide comment
@EisenbergEffect

EisenbergEffect May 14, 2017

Member

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.

Member

EisenbergEffect commented May 14, 2017

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

This comment has been minimized.

Show comment
Hide comment
@MattGiesa

MattGiesa Jul 15, 2017

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

Thanks

MattGiesa commented Jul 15, 2017

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

This comment has been minimized.

Show comment
Hide comment
@mttmccb

mttmccb Jul 15, 2017

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

mttmccb commented Jul 15, 2017

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

@mttmccb

This comment has been minimized.

Show comment
Hide comment
@mttmccb

mttmccb 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

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

davismj added a commit to davismj/router that referenced this issue Jul 25, 2017

davismj added a commit to davismj/router that referenced this issue Jul 25, 2017

feat(activation): call can/Deactivate with navigationInstructions
This enables the consumer to inspect the navigation instructions and make a decision on whether or not a route can be deactivated based on the incoming navigation instructions.

Closes #493

@davismj davismj closed this in #505 Aug 23, 2017

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