问题描述
我正在使用react钩子和redux。我已经用App
包装了BrowserRouter
组件:
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<BrowserRouter>
<App />
</BrowserRouter>
</Provider>
</React.StrictMode>,document.getElementById('root')
);
在App
组件中,我正在使用useHistory
钩子来获取history
对象:
const history = useHistory();
useEffect(()=>{
history.listen((location,action) => {
// clear alert on location change
dispatch(alertActions.clear());
});
但是我想访问我用于登录的动作创建者文件中的history
对象,以便登录后可以执行此操作:
history.push('/');
我该如何实现?我必须使用Router
而不是BrowserRouter
吗?
编辑:
我必须使用Router
而不是BrowserRouter
,并且它现在可以正常工作。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)