我正在使用 react-router 进行路由,并使用 hashHistory 选项,以便我可以从浏览器刷新页面或指定我现有路由之一的 url 并登陆正确的页面。它工作正常,但我在 url 中看到这样的哈希: http://localhost/#/login?_k=ya6z6i
这是我的路由配置:
ReactDOM.render((
<Router history={hashHistory}>
<Route path='/' component={MasterPage}>
<IndexRoute component={LoginPage} />
<Route path='/search' component={SearchPage} />
<Route path='/login' component={LoginPage} />
<Route path='/payment' component={PaymentPage} />
</Route>
</Router>),
document.getElementById('app-container'));
原文由 Dennis Nerush 发布,翻译遵循 CC BY-SA 4.0 许可协议
您是否尝试过 browserHistory 选项?您还可以从浏览器刷新页面或指定现有路线之一的 url 并登陆正确的页面。
此外,考虑到 react-router github doc,hashHistory 不适用于生产用途。
https://github.com/ReactTraining/react-router/blob/master/docs/guides/Histories.md#browserhistory
我应该使用 hashHistory 吗?