React-router: Animated Transitions can't use HashRouter

Created on 15 Jun 2017  路  1Comment  路  Source: ReactTraining/react-router

When I use HashRouter instead of BrowserRouter in official case.The animation transition didn't work.
official case

Most helpful comment

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.

  • The reason for this is that hash history doesn't use 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.

>All comments

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.

  • The reason for this is that hash history doesn't use 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.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

stnwk picture stnwk  路  3Comments

sarbbottam picture sarbbottam  路  3Comments

misterwilliam picture misterwilliam  路  3Comments

Waquo picture Waquo  路  3Comments

hgezim picture hgezim  路  3Comments