Skip to content

feat: allow routeExit to cancel further routing, pushState#228

Open
barronhagerman wants to merge 1 commit intomasterfrom
route-exit-cancel-support
Open

feat: allow routeExit to cancel further routing, pushState#228
barronhagerman wants to merge 1 commit intomasterfrom
route-exit-cancel-support

Conversation

@barronhagerman
Copy link
Copy Markdown
Contributor

Summary

This adds the ability to return false in a routeExit() function to stop further routing. A common example of a use case for this feature is to enable checking for unsaved changes and showing a confirmation dialog before exiting the route to allow the user to confirm whether they want to discard their changes or not.

  • Adds new shouldPushState accessors to Context to allow control of whether pushState() should be called when setting handled from false to true
  • Updates RouteTreeNode.prototype.activate() so returning false in a routeEnter() always prevents any further routing, including any further routeExit or routeEnter() functions and
    • The current behavior stops further routeEnter handlers from being called, but does not necessarily stop the unhandled route handler from firing. Generally, the top-level routeEnter() sets context.handled = true, but that may not always be the case. Setting both of these context properties fixes that.
  • Adds logic for routeExit() handlers to prevent further routing by returning false like routeEnter handlers. By setting the context.shouldPushState to false, context.handled to true, and returning, any further routeExit or routeEnter functions are prevented.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant