reactjs - React 刷新页面或返回上一个 url(除了 home '/' 路由)不起作用
问题描述
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
import { useHistory } from 'react-router-dom';
const Installer = () => {
const classes = useStyles();
const history = useHistory();
return (
<Router history={history}>>
<Switch>
<Route exact path='/' component={zz} />
<Route path='/xx' component={xx} />
<Route path='/yy' component={yy} />
</Switch>
</Router>
)
}
export default Installer
刷新页面或返回不起作用。如果我手动将 url 输入到除基本 url 之外的特定页面,那也不起作用。
解决方案
我建议不要useHistory()
使用goBack()
推荐阅读
- regex - 正则表达式由不在双/单引号内的空格分割?
- html - 离子范围分色
- javascript - 当我试图获取 HTML 元素的属性值时没有返回
- python - 需要帮助尝试简化此算法以将任意大的 2d 平面上的点映射到唯一整数
- r - 使用形状文件下载 R 中国家/地区的 MODIS 产品数据
- css - 在网格容器中清空无法解释的(不需要的)空间
- html - 即时更新表单字段 - Django
- sql - 找不到列或没有为查询指定列 - Progress SQL 接口
- git - 从存储库的分支引导
- docker - GitHub Actions 缓存是否检测到基础 Docker 映像中的更改?