solidjs / solid-router

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

Provide a way to hook on routing start/end #102

Open fogzot opened 2 years ago

fogzot commented 2 years ago

When using, for example solid-transition-group to implement enter/exit transitions on route changes, e.g.,

...
    <Transition {transitionProps}>
        <Routes />
    </Transition>
...

it is useful to use a different set of transitionProps for the enter and the exit animations. The exact set of props can be determined by comparing the old route to the new one (for example, going from master to detail usually involves an enter transition, while going back an exit one) and currently there is no way to do that. For example useLocation() and other hooks trigger after the routing transaction has ended: to late to change in any way the props passed to <Transition> or to inlfuence the DOM changes or CSS animations.

I think that implementing an hook that triggers at the start of the routing transaction would be extremely useful to help synchronize DOM animations with route changes.

njarraud commented 2 years ago

It would be quite useful. It is possible to get a "routeChangeComplete" event by listening to the location change. But I didn't manage to find a trick to get some sort of "routeChangeStart" event. isRouting changing from false to true only does the trick the first time the destination page is loaded. If user comes back to the page later it always remain on false.

g-mero commented 1 year ago

+1 really need this

sonovice commented 1 year ago

That is actually what keeps me from going down the solid route (pun intended) - I need to animate page transitions in a mobile app and be able to make "forward" and "backward" animations (slide right vs left).

Reverier-Xu commented 5 months ago

Any progress on this issue?