如何从LoginAction重定向到仪表板?我正在使用React-router 1.0。
var Dispatcher = require('../dispatcher/appDispatcher');
var LoginConstants = require('../constants/LoginConstants');
var LoginActions ={
LoginUser: function(data){
localStorage.myapptoken= JSON.stringify(data);
if(data.value != undefined)
{
//TODO: Navigate to dashboard.
}
Dispatcher.dispatch({
actionType: LoginConstants.AUTHENTICATE_USER,
authResponse: data
});
}
};
module.exports = LoginActions;
答案 0 :(得分:1)
您是否尝试过history?
var history = require('history')
...
history.replaceState(null, '/dashboard')
来自Navigating Outside of Components
注意,doc说你应该自己初始化历史对象:
var createBrowserHistory = require('history/lib/createBrowserHistory')
...
<Router history={createBrowserHistory()}>{routes}</Router>