网站搜索

javascript - 为 Hash Router 的 React 网站添加子路径


我们正在使用带有 hash-router 的 React 网站,本地 URL 看起来类似这样:

http://0.0.0.0:4321/#/

我想总是为 URL 添加一个子路径,并且它应该像这样工作:

http://0.0.0.0:4321/somepath/#/
http://0.0.0.0:4321/somepath/#/somepage

我总是想要以上格式的 URL。虽然我在 Hashrouter 中使用了基本路径,如下所示:

<HashRouter basename={'/somepath'}>

我得到的 URL 是这种格式:

http://0.0.0.0:4321/#/somepath/
http://0.0.0.0:4321/#/somepath/somepage

我是否需要在项目的其他地方进行任何更改,以始终使用此路径?我尝试在沙盒中重现这个问题:https://codesandbox.io/s/react-typescript-forked-jk8e9?file=/src/App.tsx,但它似乎无法正常工作。