それは、onChange
1つの場所で認証を処理することも
onChange: function(prevState, {location:{pathname:next}}, replace)=> {
if(!logined && next !== '/login') {
replace('/login');
}
}
を試してみてくださいreplace
を呼び出しますので、あなたはHOCを使用することができますinfinitlyその
const CheckAuth = (isLogined, redirectPath) => Component =>
class CheckAuth extends React.Component {
componentWillUpdate(nextProps, nextState){
//Check auth on change
this.checkAuth(nextProps);
}
componentWillMount(){
//Check auth on enter
this.checkAuth(this.props);
}
checkAuth({location}){
if(!isLogined && location.pathname!==redirectPath) {
browserHistory.replace(redirectPath);
}
}
render(){
return (<Component {...this.props}/>);
}
};
のようなものを変更します
およびAppコンポーネント
class App extends React.Component { ... }
export default CheckAuth(isLogined,'/login')(App);
また、redux-auth-wrapper
と方法があります