reactjs - 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>
);
欢迎您对我的代码提出其他改进建议!
解决方案
推荐阅读
- javascript - 有谁知道为什么我从我的 vue 组件查看本地存储时收到此消息
- delphi - 预期 Blob 获得了 Clob 休息服务
- javascript - 尝试 setState 时未在 componentDidMount 中获取对象
- salesforce - 跨域 UTM 并使用 GTM 发送到 Salesforce
- kotlin - 我怎样才能删除这个未解决的参考?
- artificial-intelligence - 广度优先搜索解决路径
- python - 发送电子邮件/使用字典
- python - 定义形态:使用 Wand 合并多形态内核的结果
- python - 在 python pandas 中,计算特定列中的整数并计算特定列中的所有元素
- java - Java 8 是否提供了一种根据特定条件重复功能的好方法?