如何解决React.js HashRouter 404页面
我在用React 404
实现功能全面的HashRouter
页面时遇到问题。
routes.tsx
export const Routes = () => (
<HashRouter>
<Switch>
<Route path="/" exact={true} component={Home} />
<Route path="/route1" component={Route1} />
<Route path="/route2" component={Route2} />
<Route component={ErrorPage} />
</Switch>
</HashRouter>
);
app.tsx
<>
...
<Routes />
...
</>
当前行为:
- 在地址栏中输入
{url}/#/{non-existing-route}
时,行为正确-浏览器显示ErrorPage
- 在地址栏中输入
{url}/{non-existing-route}
时,行为不正确-浏览器将网址更改为{url}/{non-existing-route}#/
并显示Home
页面。
我希望在两种情况下都显示ErrorPage
。
当我使用BrowserRouter
时不会发生此问题,但是我必须在这里使用HashRouter
。
谢谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。