How to redirect after success from ajax call using React-router-component?

后端 未结 3 1271
臣服心动
臣服心动 2021-02-14 10:23

I am building a application using Facebook flux architecture of React JS. I have build the basic part of app where I have a login form. I am fetching t

3条回答
  •  鱼传尺愫
    2021-02-14 10:45

    You need to use the transitionTo function from the Navigation mixin: http://git.io/NmYH. It would be something like this:

    // I don't know implementation details of the store,
    // but let's assume it has `login` function that fetches
    // user id from backend and then calls a callback with 
    // this received id
    var Store = require('my_store');
    var Router = require('react-router');
    
    var MyComponent = React.createClass({
      mixins: [Router.Navigation],
    
      onClick: function() {
        var self = this;
        Store.login(function(userId){
          self.transitionTo('dashboard', {id: userId});
        });
      },
    
      render: function() {
        return: ;
      }
    });
    

提交回复
热议问题