Animate page transition
I am trying to animate route changes with Motion One. However, I seem to not get the overall logic of Solid Router since no route is shown at all in my MWE:
Any help would be a appreciated.
8 Replies
Maybe instead of wrapping the route in Motion component you may create a layout which wraps the children (in this case the whole pages) in the Motion component.
The Router component expects Route components as children.
https://docs.solidjs.com/solid-router/concepts/layouts#layouts
Thanks for the hint. I am still having a hard time to get it right. Only the initial page load is animated, other transitions are not.
Current code:
Oh yeah sure, Layouts persist on route changes.
This should do the trick for a root layout:
Thanks! This kinda works, but now I have a blank screen between two pages. The animation for the next page only starts after the exit animation of the previous one finished. If I remove
exitBeforeEnter
, there is no exit animation.
It seems as if it impossible to trigger exit
and animate
at the same time with solid router :/Yes, that's the nature of routing. You can only show one route at a time.
If I get your use case correctly you want to show two components exiting and entering at the same time: Then I would use somthing like a carousel component (like https://shadcn-solid.com/docs/components/carousel) and instead of using the hashrouter you could use the
useSearchParams
hook to control the carouselAh, got it. So I have to have all pages of my app already in the DOM, otherwise things vanish. Thank you!
I took your ideas and came up with this, kinda abusing the router:
Legit solution 👍
Now I have to figure out how to change the transformations dynamically based on previous and next route. Basically "slide right" if I go deeper in the path structure (e.g. "/" -> "/dashboard/") and "slide left" if I go up.
Done. FYI: