A React component that provides Vue-like keep-alive caching for react-router v4+ routes. Version 1.13.0 is the latest stable release; the package is maintained sporadically with low release cadence. It uses a `CacheRoute` wrapper that hides instead of unmounts the component when the route becomes unmatched, preserving component state and DOM. It also provides a `CacheSwitch` to replace `Switch` for proper caching behavior. Alternatives include `react-activation` for a standalone `<KeepAlive>` component.
npm install react-router-cache-routeNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage: replace Route with CacheRoute and Switch with CacheSwitch to enable route caching.
Replace <Switch> with <CacheSwitch> from 'react-router-cache-route'.
Use with react-router-dom v4 or v5. For v6, consider other caching solutions like react-activation.
Set when='always' to cache on both forward and backward navigation.
Ensure behavior returns { style: { display: 'none' } } or similar when cached, and undefined or empty object when not.Use import CacheRoute from 'react-router-cache-route'.
Change to: import CacheRoute from 'react-router-cache-route'
Replace Switch with CacheSwitch from this package: import { CacheSwitch } from 'react-router-cache-route'Wrap your application in a BrowserRouter or HashRouter from react-router-dom
This is a known bug in some versions; upgrade to latest or avoid passing unknown props. Check GitHub issues for workarounds.