我有一个看起来像这样的路由器
<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 更新了 url 并将我导航到 'something.do?phase=something',但我没有看到 Route 的 history.location 得到更新。因此(我认为),当我单击页面“something.do?phase=something”上的某个链接时,只有页面的 url 发生变化,但不会导航到该新页面。
我检查了Programmatically navigate using react router V4和Programmatically navigate using react router,但仍然没有到达任何地方。请帮忙。