3
我正在使用此反應redux starter,我想知道如何將所有api 500錯誤重定向到頁面?如何使用react-redux將錯誤500全局重定向到頁面
我正在使用此反應redux starter,我想知道如何將所有api 500錯誤重定向到頁面?如何使用react-redux將錯誤500全局重定向到頁面
還原啓動器默認安裝了react-router-redux
和redux-thunk
。
由於您沒有提供任何代碼,因此我不確定是否進行了API調用,但是如果您可以將商店注入到您的API包裝中,也許您可以通過您的redux商店調度路由器操作。
假設你正在使用某種形式的API包裝的和的thunk,你可以做這樣的事情:
import { push } from 'react-router-redux';
function myThunkFunction() {
return dispatch => axios.get(...).catch((error) => {
/** insert logic to determine 500 error **/
if (500error) {
dispatch(push('http://example.com/error/500'));
}
});
}
你能趕在前端的錯誤?如果可以的話,用你想要的頁面推到歷史記錄。您可以在反應路由器的文檔中查看實施細節。 –