最近在做项目的时候遇到了如下错误
react-router刷新页面Cannot GET 问题
并在控制台看到了如下的报错
react-router刷新页面Cannot GET 问题
我先是按照控制台的错误搜索,得出的结果都是对meta头部进行设置,允许资源请求,但是问题依然没有解决,偶然间改变了想法,会不会是路由的问题呢,一搜还真是,这是因为没有历史记录
添加HashRouter即可

import { HashRouter } from 'react-router-dom';

  <HashRouter>
        {/*<Route>*/}
            <Route  exact path="/" component={ App } />

            <Route  path="/aboutMe" component={aboutMe} />
            <Route  path="/myBlog" component={myBlog} />
            <Route  path="/myTrip" component={myTrip} />
            <Route  path="/aboutWebsite" component={aboutWebsite}/>


        {/*</Route>*/}
  </HashRouter>

react-router刷新页面Cannot GET 问题
最终url会被打上#,问题解决,说是因为打上#后不再会请求服务器资源

问题参考:https://stackoverflow.com/questions/27928372/react-router-urls-dont-work-when-refreshing-or-writing-manually

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-01-18
  • 2021-08-13
  • 2021-12-03
猜你喜欢
  • 2021-12-19
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2021-11-29
相关资源
相似解决方案