你必須要路由器傳遞給你的終極版咚行動的創建者(你的代碼PICE不是一個動作,但我寫行動的創建者)。例如,它可能看起來像:
export function loginSuccess(router, response){
return (dispatch, getState) => {
dispatch({ response, type: types.LOGIN });
router.transitionTo("/profile")
};
}
您是否有權訪問您的路由器以調用此操作創建者?它在那裏可用嗎?如果是的話那麼你有沒有這樣的事情(我不知道什麼是response
):
this.props.dispatch(loginSuccess(response));
,你必須將其更改爲:
this.props.dispatch(loginSuccess(this.context.router, response));
我假設你可以訪問路由器通過上下文。
因爲你不顯示你如何調用這個動作,我只是猜測。我希望我的指導能幫助你。
還有一件事。新的react-router api在路由器中沒有transitionTo方法!我不知道你是否使用新的或舊的API。但是,如果你得到錯誤,如:
調用transitionTo
失敗: 'location.search.substring不是一個函數'
隨後還更改:
router.transitionTo("/profile")
到:
router.push("/profile")
'router'應該傳入'this.props'。 –
這是在我的行動..我怎麼能通過this.props .. – aryan
啊,沒有仔細閱讀。你使用'redux-router'嗎? –