緩存頁(yè)面內(nèi)容,跳到下一頁(yè)再次返回衔彻,滾動(dòng),點(diǎn)擊active都保持和離開(kāi)時(shí)候的狀態(tài)一致
npm install react-router-cache-route --save
示例代碼:
import React from "react";
import ReactDom from "react-dom";
import { HashRouter, Route, hashHistory, Redirect } from "react-router-dom";
import {CacheSwitch, CacheRoute} from 'react-cache-router';
class App extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<HashRouter history={hashHistory}>
<CacheSwitch>
<CacheRoute path="/a" component={sourceIndex}></CacheRoute>
<Route path="/b" component={sourceSearch}></Route>
<Redirect to="/"></Redirect>
</CacheSwitch>
</HashRouter>
)
}
}
ReactDom.render(<App />, document.getElementById("root"));
注意:
緩存語(yǔ)句要寫(xiě)在CacheSwitch里面