-
Notifications
You must be signed in to change notification settings - Fork 147
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
Support for blocking navigation (useBeforeLeave) #186
Conversation
…#182) fix solidjs#181 Using reactive class can have unexpected behavior when used in combination with a classList.
Have added "from" path to event args as it proved useful in real-world testing. |
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 |
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)
This looks really good, and it taps in before Transitions so I think we are good here. Love it. |
Adds this...
useBeforeLeave
useBeforeLeave
takes a function that will be called prior to leaving a route. The function will be called with:navigate
.navigate
.true
to 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-router
to extend its built-in integrations. This branch includes this addtional behavior.Finally, users may wish to block full page document navigations (ie using window
beforeunload
event) but that should be handled in application code directly (outside the scope of the router).