Support for blocking navigation (useBeforeLeave)#186
Merged
ryansolid merged 11 commits intosolidjs:mainfrom Nov 21, 2022
Merged
Support for blocking navigation (useBeforeLeave)#186ryansolid merged 11 commits intosolidjs:mainfrom
ryansolid merged 11 commits intosolidjs:mainfrom
Conversation
…#182) fix solidjs#181 Using reactive class can have unexpected behavior when used in combination with a classList.
Contributor
Author
|
Have added "from" path to event args as it proved useful in real-world testing. |
Contributor
Author
|
Hmm, I think there is an issue here requiring a bit of a code restructure. I set up the leave handlers globally - but they should be per |
Contributor
Author
|
Okay the latest commit makes the BeforeLeave subscribers specific to the Router instance. BeforeLeave management can be created by either:
Note that 2 still requires a change to the integrations which I haven't included in this PR - but do have in this branch (and are using in production O_O!!) |
…uter (and reduce work for integrations)
filipjnc
approved these changes
Nov 15, 2022
Member
|
This looks really good, and it taps in before Transitions so I think we are good here. Love it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds this...
useBeforeLeave
useBeforeLeavetakes a function that will be called prior to leaving a route. The function will be called with:navigate.navigate.trueto skip running the leave handlers again (ie force navigate without confirming).Example usage:
NOTE LIMITATIONS
This PR only adds support to block navigations originating from the router (eg
<Link>,useNavigate()).Blocking navigations originating in the browser (back/forward, plain anchors) can also be done and requires either a custom path/hash integration, or
solid-routerto extend its built-in integrations. This branch includes this addtional behavior.Finally, users may wish to block full page document navigations (ie using window
beforeunloadevent) but that should be handled in application code directly (outside the scope of the router).