keep-alive-route
v0.1.2
Published
KeepAliveRoute for react-router-dom
Downloads
4
Maintainers
Readme
keep-alive-route
why do we need KeepAliveRoute component?
When route change in react-router-dom
, old component was destroyed and new component matched the route will be created.
That is ok.
But sometimes we want to keep old component's state when route change. It's useful to let user do nothing to view same page when come back.
how to implement KeepAliveRoute?
Maybe two ways:
when route change, don't destroy old component. ✅
save old component's state data. Use the old data to restore the component's state when it is created again.
KeepAliveRoute adopt first way. This method is simple and straightforward, but overuse may cause memory leaks.
how to use KeepAliveRoute?
import KeepAliveRoute from "keep-alive-route";
KeepAliveRoute is completely based on react-router-dom.Route. The usage is exactly the same as it.