I need to do some animations within nested routes (using react-transition-group v5.2.0, for what that is worth).
Following the example, in the react-transition-group docs I am able to get regular routes animation going using CSSTransition
, but the same cannot be said for nested routes. They simply do not animate and their expected classes from CSSTransition are not injected in the component as expected (*-enter
, *-enter-active
, *-exit
, *-exit-active
).
My current component with nesting routes looks like the following:
function Example () {
const { params } = useRouteMatch() || {}
const history = useHistory()
return (
<>
[EXISTING_CONTENT]
<button onClick={()=> goToTheNextRoute()}>Click me!</button>
<Route path="/example/:nestedId">
{({ location }) => {
const { pathname } = location
return (
<CSSTransition
in={pathname.includes(params?.nestedId)}
timeout={500}
classNames="nested-animation"
mountOnEnter
unmountOnExit
>
<div className="nested-animation">
My nested routes I'd like to animate at every click:
<h3>Current Nested Route: {params?.nestedId}</h3>
</div>
</CSSTransition>
)
}}
</Route>
</>
)
}
Here is also a sandbox app which is also based off the simple route example from the documentation.
What am going for is to have an animation on the div of className nested-animation
every time the nested route is updated.