Programmatically navigate using react router

后端 未结 30 2391
無奈伤痛
無奈伤痛 2020-11-21 05:18

With react-router I can use the Link element to create links which are natively handled by react router.

I see internally it calls t

30条回答
  •  醉梦人生
    2020-11-21 05:34

    If happen to pair RR4 w/ redux through react-router-redux, use the routing action creators from react-router-redux is a option as well.

    import { push, replace, ... } from 'react-router-redux'
    
    class WrappedComponent extends React.Component {
      handleRedirect(url, replaceState = true) { 
        replaceState 
          ? this.props.dispatch(replace(url)) 
          : this.props.dispatch(push(url)) 
      }
      render() { ... }
    }
    
    export default connect(null)(WrappedComponent)
    

    If use redux thunk/saga to manage async flow, import the above action creators in redux actions and hook to react components using mapDispatchToProps might be better.

提交回复
热议问题