React Router 1.0如何在flux操作中重定向写重定向代码

时间:2015-11-06 05:54:59

标签: reactjs react-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;

1 个答案:

答案 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>