STRML / react-router-component

Declarative router component for React.
http://strml.viewdocs.io/react-router-component
MIT License
873 stars 94 forks source link

Retaining route handler state during routing. #175

Closed kansi closed 8 years ago

kansi commented 8 years ago

I have the following router

<Locations  hash >
<Location path="/" handler={SideBarMainList1} />
<Location path="/group_list" handler={SideBarGroupList} />
</Location>

I visit /group_list and change the state of a dropdown list in this route and then go back to /. Now when i come back again to /group_list i cannot see the pervious state being retained.

It seems that with each route change the corresponding component is re-rendered. How can i just un-mount the component and then remount it keeping its state intact ?

jsg2021 commented 8 years ago

Make your state external to the component... like in Flux's Stores. The component's state will be lost on unmount. That's React, not the router.

STRML commented 8 years ago

Agreed, this is not an RRC issue, this is the way React works and you will run into it with any component that conditionally renders another component.