When I use HashRouter instead of BrowserRouter in official case.The animation transition didn't work.
official case
The issue is that <HashRouter>does not add the key property to locations*. That means that when you try to run the example as given (using location.key), the key is always undefined, which means that the <CSSTransitionGroup> cannot tell what components are entering/leaving. If you switched this:
key={location.key}
to this
key={location.pathname}
it should work.
history.(push|replace)State to switch the location (it just uses window.location.replace), so there is no way to store a key for a location.
Most helpful comment
The issue is that
<HashRouter>does not add thekeyproperty to locations*. That means that when you try to run the example as given (usinglocation.key), thekeyis alwaysundefined, which means that the<CSSTransitionGroup>cannot tell what components are entering/leaving. If you switched this:to this
it should work.
history.(push|replace)Stateto switch the location (it just useswindow.location.replace), so there is no way to store akeyfor a location.