Animate routing
Do classic animations with react-router-dom.
Basic usage#
Just replace your Switch by AnimateSwitch, your Route by AnimateRoute and set animationType prop on AnimateSwitch (fade by default).
Example:
Advanced usage#
Nested routing#
If you have nested routing in your app, there is a problem (fixable): when a child route changes, it will re render parent route as well.
To prevent this you can use AnimateLink (extends NavLink of react-router-dom) in combination with useAnimateKey() hook and animationKey prop of AnimateSwitch component.
Example:
Different animations between routes#
By default, AnimateSwitch will set same animation for all its contained routes.
If you want a route to make a different animation, you juste have to set animationType on the AnimateRoute concerned.
Custom animations#
You can create your own animations, because AnimateSwitch and AnimateRoute inherite some framer-motion props.
See API doc of these components for more detail.
You can mix nested routing, different animations between routes and custom animations without any problem.
Animations available#
fadescaleslideUpslidedownslideLeftslideRight
Use them with
animationTypeprop ofAnimateSwitchandAnimateRoute