首页 > 解决方案 > React on GitHub Pages refresh url not found

问题描述

最近我在 Github Pages 上托管了我的 react 应用程序,它似乎可以工作,但是当我刷新页面时,我得到 404 Not Found。我理解为什么会发生这种情况,因为我的 GitHub 在此 URL 上找不到任何应用程序,尽管它对我的应用程序有效。我读过我可以用 HashRouter 修复它,但问题是反应路由器官方文档现在已经关闭了几天。如果您对HashRouter有任何经验或有不同的解决方案,请分享!

在我的 App.js 中返回

return (
  <div>
    <Navigation redirect={this.redirect} />
    <HashRouter>
      <Switch>
        <Route path='/Login' render={(props) => requireAnonymous(Login, props)} />
        <Route path='/Register' render={(props) => requireAnonymous(Register, props)} />
        <Route path='/Calendar' render={(props) => requireAuthentication(Calendar, props)} />
        <Route path='/Todo/:date' render={(props) => requireAuthentication(TodoContainer, props)} />
      </Switch>
    </HashRouter>
  </div>
);

欢迎您对我的代码提出其他改进建议!

标签: reactjsgithub-pagesreact-router-dom

解决方案


推荐阅读