solidjs / solid-router

A universal router for Solid inspired by Ember and React Router
MIT License
1.14k stars 147 forks source link

Extend useBeforeLeave for browser initiated events (eg back/forward) #320

Closed Brendan-csel closed 8 months ago

Brendan-csel commented 10 months ago

This PR extends useBeforeLeave blocking to include router initiated navigations such as back/forward.

See issue https://github.com/solidjs/solid-router/issues/277

We've been using this approach in production for over year now - albeit with the 0.8 router generation and hash integration. Today I rebased this onto 0.10.1 and did some basic testing.

One aspect that might be contentious is using _depth on history state to detect navigation type.

Even if not merged, hopefully this PR offers some guidance for others needing this feature.

ryansolid commented 10 months ago

This is definitely a feature that I feel is missing from the router. The contentious part you are talking about is backing out of the app right? Especially after browser refresh as you won't have the history anywhere else? I've used something like depth in the past to solve this so it seems reasonable to me.

What's the concern?

Brendan-csel commented 10 months ago

What's the concern?

Really just that this pollutes window.history.state with a _depth property to enable this feature.