Keep react-router routed-components for all history states

Viewed 2925

I make a mobile application with Cordova. Use the react-router@2.0.0 + ReactCSSTransitionGroup to implement the "card deck" animation. I have a strict Routes tree without the possibility of circular links.

To improve performance and save the state of the previous route-components, I would like to keep the whole history of them with unmounting only on pop-state or replace-state.

How to do it?

3 Answers

Ionic provides this feature with their IonRouterOutlet component to allow transitions between pages. It's not quite trivial to follow the implementation but maybe you can take a look at their Repo.

What they are doing is basically wrap React's BrowserRouter and keep all routes rendered - toggling their visibility via css.

Note that this is not meant to improve performance but allow transitions. Rather than improving performance it might actually hinder it. For example to clean-up resources via useEffect cleanup functions or componentWillUnmount().

Related