
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
react-router-cache-route
Advanced tools
Route with cache for react-router like keep-alive in Vue.
Will cache the Route ONLY WHILE GOING FOWARD
npm install react-router-cache-route --save
or
yarn add react-router-cache-route
Can use CacheRoute, or
Using cacheComponent work with Route's children prop
DO NOT PUT IT IN Switch COMPONENT
import React from 'react'
import { HashRouter as Router, Switch, Route } from 'react-router'
import CacheRoute, { cacheComponent } from 'react-router-cache-route'
import List from './components/List'
import Item from './components/Item'
import List2 from './components/List2'
import Item2 from './components/Item2'
const App = () => (
<Router>
<CacheRoute exact path="/list" component={List} />
<Route exact path="/list2" children={cacheComponent(List2)} />
<Switch>
<Route exact path="/item/:id" component={Item} />
<Route exact path="/item2/:id" component={Item2} />
</Switch>
</Router>
)
export default App
Component with CacheRoute will accept one prop named cacheLifecycles witch contains two functions to inject customer Lifecycle didCache and didRecover
import React, { Component } from 'react'
export default class List extends Component {
constructor(props, ...args) {
super(props, ...args)
props.cacheLifecycles.didCache(this.componentDidCache)
props.cacheLifecycles.didRecover(this.componentDidRecover)
}
componentDidCache = () => {
console.log('List cached')
}
componentDidRecover = () => {
console.log('List recovered')
}
render() {
return (
// ...
)
}
}
FAQs
cache-route for react-router base on react v15+ and router v4+
We found that react-router-cache-route demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.