Gathering detailed insights and metrics for @remax/react-router-cache-route
Gathering detailed insights and metrics for @remax/react-router-cache-route
Gathering detailed insights and metrics for @remax/react-router-cache-route
Gathering detailed insights and metrics for @remax/react-router-cache-route
Route with cache for react-router V5 like <keep-alive /> in Vue
npm install @remax/react-router-cache-route
Typescript
Module System
Node Version
NPM Version
67.3
Supply Chain
93.5
Quality
80.4
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
95,535
Last Day
37
Last Week
1,055
Last Month
3,394
Last Year
27,810
MIT License
1,175 Stars
143 Commits
113 Forks
10 Watchers
2 Branches
5 Contributors
Updated on Jun 18, 2025
Minified
Minified + Gzipped
Latest Version
1.8.4
Package Id
@remax/react-router-cache-route@1.8.4
Size
838.06 kB
NPM Version
6.14.4
Node Version
13.12.0
Published on
May 13, 2020
Cumulative downloads
Total Downloads
Last Day
-67.5%
37
Compared to previous day
Last Week
-7.5%
1,055
Compared to previous week
Last Month
38.3%
3,394
Compared to previous month
Last Year
80.6%
27,810
Compared to previous year
English | 中文说明
Route with cache for react-router
like keep-alive
in Vue.
If you want <KeepAlive />
only, try react-activation
React v15+
React-Router v4+
Using Route
, component can not be cached while going forward or back which lead to losing data and interaction
Component would be unmounted when Route
was unmatched
After reading source code of Route
we found that using children
prop as a function could help to control rendering behavior.
Hiding instead of Removing would fix this issue.
1npm install react-router-cache-route --save 2# or 3yarn add react-router-cache-route
Replace Route
with CacheRoute
Replace Switch
with CacheSwitch
(Because Switch
only keeps the first matching state route and unmount the others)
1import React from 'react' 2import { HashRouter as Router, Route } from 'react-router-dom' 3import CacheRoute, { CacheSwitch } from 'react-router-cache-route' 4 5import List from './views/List' 6import Item from './views/Item' 7 8const App = () => ( 9 <Router> 10 <CacheSwitch> 11 <CacheRoute exact path="/list" component={List} /> 12 <Route exact path="/item/:id" component={Item} /> 13 <Route render={() => <div>404 Not Found</div>} /> 14 </CacheSwitch> 15 </Router> 16) 17 18export default App
name | type | default | description |
---|---|---|---|
when | String / Function | "forward" | Decide when to cache |
className | String | - | className prop for the wrapper component |
behavior | Function | cached => cached ? { style: { display: "none" }} : undefined | Return props effective on the wrapper component to control rendering behavior |
cacheKey | String | - | For imperative control caching |
multiple (React v16.2+) | Boolean / Number | false | Allows different caches to be distinguished by dynamic routing parameters. When the value is a number, it indicates the maximum number of caches. When the maximum value is exceeded, the oldest updated cache will be cleared. |
unmount (UNSTABLE) | Boolean | false | Whether to unmount the real dom node after cached, to save performance (Will cause losing the scroll position after recovered, fixed with saveScrollPosition props) |
saveScrollPosition (UNSTABLE) | Boolean | false | Save scroll position |
CacheRoute
is only a wrapper component that works based on the children
property of Route
, and does not affect the functionality of Route
itself.
For the rest of the properties, please refer to https://reacttraining.com/react-router/
when
The following values can be taken when the type is String
PUSH
or REPLACE
action in react-routerPOP
action in react-routerWhen the type is Function
, the component's props
will be accepted as the first argument, return true/false
to determine whether to cache.
name | type | default | description |
---|---|---|---|
which | Function | element => element.type === CacheRoute | <CacheSwitch> only saves the first layer of nodes which type is CacheRoute by default, which prop is a function that would receive a instance of React Component, return true/false to decide if <CacheSwitch> need to save it, reference #55 |
Component with CacheRoute will accept one prop named cacheLifecycles
which contains two functions to inject customer Lifecycle didCache
and didRecover
1import React, { Component } from 'react' 2 3export default class List extends Component { 4 constructor(props) { 5 super(props) 6 7 props.cacheLifecycles.didCache(this.componentDidCache) 8 props.cacheLifecycles.didRecover(this.componentDidRecover) 9 } 10 11 componentDidCache = () => { 12 console.log('List cached') 13 } 14 15 componentDidRecover = () => { 16 console.log('List recovered') 17 } 18 19 render() { 20 return ( 21 // ... 22 ) 23 } 24} 25
You can manually control the cache with cacheKey
prop and dropByCacheKey
function.
1import CacheRoute, { dropByCacheKey, getCachingKeys } from 'react-router-cache-route' 2 3... 4<CacheRoute ... cacheKey="MyComponent" /> 5... 6 7console.log(getCachingKeys()) // will receive ['MyComponent'] if CacheRoute is cached which `cacheKey` prop is 'MyComponent' 8... 9 10dropByCacheKey('MyComponent') 11...
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More