Animate routing
Do classic animations with react-router-dom.
#
Basic usageJust replace your Switch
by AnimateSwitch
, your Route
by AnimateRoute
and set animationType
prop on AnimateSwitch
(fade by default).
Example:
#
Advanced usage#
Nested routingIf 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 routesBy 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 animationsYou 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 availablefade
scale
slideUp
slidedown
slideLeft
slideRight
Use them with
animationType
prop ofAnimateSwitch
andAnimateRoute