我有一个路由器,它看起来像这样更新路由器的历史位置(使用反应路由器-DOM)
<Router>
<Switch>
<Route path="abc.do" render={() => <SetupAppInitialLoad pageKey="abc" />} />
<Route path="xyz.do" render={() => <SetupAppInitialLoad pageKey="xyz" />} />
</Switch>
</Router>
我有很多Route
像这些内<Switch>
。当用户点击按钮/链接时,我正在使用redux处理状态并从一些组件分派异步操作。
export const asyncExampleAction =() => {
return (dispatch, getState) => {
//logic to send inputs to server comes here
.then(checkStatus)
.then(parseJSON)
.then((data) => {
if (success case) {
history.push(`something.do?phase=something`);
} else {
//handle error logic
}
})
.catch((error) => {
console.log(error);
});
}
}
现在,我面临的问题是,即使history.push更新网址并浏览我“something.do?phase=something”,但我看不到路的history.location得到更新。正因为如此(我认为),当我点击页面上的某个链接'something.do?phase=something'时,只有页面的url会改变,但导航到新页面不会发生。
我检查了Programmatically navigate using react router V4和Programmatically navigate using react router,但仍然没有得到任何地方。请帮忙。
如何使我的组件可以访问“历史”道具。当我使用react dev工具调试我的组件时,我没有在其道具列表中看到历史记录。您能否指出我已经实施了这种方法的任何工作示例? – abhi