How to do a redirect to another route with react-router?

前端 未结 6 2205
眼角桃花
眼角桃花 2020-12-07 13:37

I am trying to do A SIMPLE using react-router ( version ^1.0.3 ) to redirect to another view and I am just getting tired.

import React from          


        
6条回答
  •  天命终不由人
    2020-12-07 14:21

    With react-router v2.8.1 (probably other 2.x.x versions as well, but I haven't tested it) you can use this implementation to do a Router redirect.

    import { Router } from 'react-router';
    
    export default class Foo extends Component {
    
      static get contextTypes() {
        return {
          router: React.PropTypes.object.isRequired,
        };
      }
    
      handleClick() {
        this.context.router.push('/some-path');
      }
    }
    

提交回复
热议问题