在Redux中间件中使用react-router进行重定向

在Redux中间件中使用react-router进行重定向,第1张

在Redux中间件中使用react-router进行重定向

如果您喜欢Redux风格的动作,该库还提供了一组动作创建者和一个 中间件来捕获它们 并将它们重定向到您的历史实例。

对于:

push(location), replace(location), go(number), goBack(), goForward()

您必须安装routerMiddleware才能使这些动作创建者正常工作。

import { routerMiddleware, push } from 'react-router-redux'// Apply the middleware to the storeconst middleware = routerMiddleware(browserHistory)const store = createStore(  reducers,  applyMiddleware(middleware))// Dispatch from anywhere like normal.store.dispatch(push('/foo'))

React Router还提供了历史记录的单例版本
(browserHistory和hashHistory),您可以从应用程序中的任何位置导入和使用。

import { browserHistory } from 'react-router'if(action.payload != undefined && action.payload.status==401){        browserHistory.push('login');        console.log('session expired'); }

btw for check auth you may use onEnter or redux-
auth-wrapper



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5615023.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存