如何创建React路由器重定向URL

时间:2016-08-13 20:09:47

标签: javascript redirect reactjs react-router

我的目标是使用reactjs触发重定向url事件。怎么可能?已经尝试过:

  successRedirect(){
      this.transitionTo('/');
  }

successRedirect(){
    this.router.transitionTo('/');          
}

2 个答案:

答案 0 :(得分:1)

使用push而不是transitionTo

this.context.router.push('/contact');

MyClass.contextTypes = {
  router: React.PropTypes.func.isRequired
}

答案 1 :(得分:-1)


    // app.js
    // a bunch of things here :D
    var routes = require('./routes');
    var RouterContainer = require('./router');

    RouterContainer.set(Router.create({
        routes: routes
    }));
    // someUtils.js
    var router = require('../router');
    router.get().transitionTo('home');