移动端开发时会遇到在列表页点击进入详情,返回后列表页刷新的情况,对用户体验很不友好。
解决方案:使用 react-keeper 完成路由的分配,以及页面组件的缓存
react-keeper 详情参考: https://blog.csdn.net/qq_37942845/article/details/104694966
1、下载相关依赖项
npm install react-keeper -s
2、app.js中相关配置
原来我们app.js中设置路由
import { Component } from 'react';
import { Link } from 'react-router-dom'
import { renderRoutes } from 'react-router-config';
import routes from './Routers/router'
render() {
return (
<div className="App">
<div className="rouer-head">
<Link to="/">首页</Link>
<Link to="/about">关于我们</Link>
</div>
<div className="router-con">
{renderRoutes(routes)}
</div>
</div>
)
};
现在更改为