React Router 1.0 如何在 flux 动作中重定向写入重定向代码
React Router 1.0 How to redirect write redirect code inside flux action
如何从 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;
你试过了吗history?
var history = require('history')
...
history.replaceState(null, '/dashboard')
来自Navigating Outside of Components
注意文档说你应该自己初始化历史对象:
var createBrowserHistory = require('history/lib/createBrowserHistory')
...
<Router history={createBrowserHistory()}>{routes}</Router>
如何从 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;
你试过了吗history?
var history = require('history')
...
history.replaceState(null, '/dashboard')
来自Navigating Outside of Components
注意文档说你应该自己初始化历史对象:
var createBrowserHistory = require('history/lib/createBrowserHistory')
...
<Router history={createBrowserHistory()}>{routes}</Router>