首页 > 解决方案 > 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 之外的特定页面,那也不起作用。

标签: reactjsreact-router

解决方案


我建议不要useHistory()使用goBack()


推荐阅读