Support for blocking navigation (via integration)#185
Support for blocking navigation (via integration)#185Brendan-csel wants to merge 3 commits intosolidjs:mainfrom
Conversation
|
To clarify why the ...in the event of a navigation being blocked, the integration (path, hash, etc) needs to revert the browser url state appropriately eg |
|
If your curious, this commit (
Okay now, after several commits and a day of tuning, we've got a branch that implements the integrations using the hook PR ...soon to be in production in our apps. https://github.com/cselnz/solid-router/tree/publish |
|
Scrapping this in favour the much more comprehensive PR #186 |
Adds minimal core support for blocking navigation. Use case is providing some control over navigating away from a route that has unsaved changes.
Leaving a route can occur in many ways - and blocking them all is challenging:
<A>componentSome of these can be handled somewhat in user land, eg by listening to
window.beforeunloadfor (5 & 6), but others need some assistance from router.In Solid's case, blocking seems relevant in two places:
a) The router internals (ie the
navigateFromRoutefunction) handles 2 & 3b) The router integration (ie suppress notifying the location has changed) handles 1.
This PR is specific to (a) and enables (b). It enables the router integration to optionally provide a
blockfunction that will bail out ofnavigateFromRoute.It is expected that
blockfunction will originate from the app, probably as an option to the integration. It is also likely theblockfunction will itself be used to support some higher-level component such as auseBlockerhook - but these may be best experimented with in userland via custom integrations. It is noteworthy the parameters to theblockfunction are the same as those used when callingnavigate. This is intentional as the app may wish to save those parameters and block immediate navigation - and then kick navigation off again in the near future - for example if the user confirms they are okay to leave the page without saving.