Tor*_*tto 9 reactjs reactjs-flux
我正在使用Facebook flux架构构建应用程序React JS.我已经构建了app的基本部分,我有一个登录表单.我从节点服务器获取结果以验证商店中的用户,我从服务器获得结果,现在我卡住了,如何在成功后将用户重定向到主页.
我已经阅读了有关反应路由器组件的信息,我能够在客户端重定向,但在从Store中的ajax获取结果时无法重定向.请帮我.
您需要使用mixin中的transitionTo函数Navigation:http://git.io/NmYH.它会是这样的:
// 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: <button onClick={this.onClick}>Get user id</button>;
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14419 次 |
| 最近记录: |