更新路由器&x27;通过调度redux操作(使用react-router-dom)设置历史位置
我有一个类似这样的路由器更新路由器&x27;通过调度redux操作(使用react-router-dom)设置历史位置,redux,react-router-dom,Redux,React Router Dom,我有一个类似这样的路由器 <Router> <Switch> <Route path="abc.do" render={() => <SetupAppInitialLoad pageKey="abc" />} /> <Route path="xyz.do" render={() => <SetupAppInitialLoad pageKey="xyz" /&
<Router>
<Switch>
<Route path="abc.do" render={() => <SetupAppInitialLoad pageKey="abc" />} />
<Route path="xyz.do" render={() => <SetupAppInitialLoad pageKey="xyz" />} />
</Switch>
</Router>
现在,我面临的问题是,尽管history.push更新了url并将我导航到“something.do?phase=something”,但我没有看到路由的history.location得到更新。正因为如此(我想),当我点击“something.do?phase=something”页面上的某个链接时,只有页面的url发生了变化,但没有导航到新页面
我检查了一下,但还是没有结果。请提供帮助。之所以会发生这种情况,是因为
react router
不直接依赖于窗口。history
,而是使用,它包装窗口。history
,并为react router
提供监听位置更新并对其作出反应的可能性
您必须使用以下选项来更新操作导航:
历史
道具从组件
传递到操作
,并使用它在其中导航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);
});
}
}