예를 들어 here을 따라 가며 기본 인증 영역 인 을 만들었습니다. 이는 내 원칙에 대해 정말 좋아하는 해결책입니다.Redux 라우터 pushState 함수가 URL 변경을 트리거하지 않음
const store = createStore(reducer);
ReactDOM.render(
<Provider store={store}>
<Router history={hashHistory}>
<Route path="/" component={App}>
<IndexRedirect to="authenticated" />
<Route path="setup" component={SetupJourney} >
<Route path="details" component={Details}/>
<Route path="account" component={AccountType}/>
</Route>
<Route path="authenticated" component={requireAuthentication(secretPage)} />
</Route>
</Router>
</Provider>,
document.getElementById('root')
);
다음 여기에 리디렉션 처리하기 위해 내 AuthenticatedComponent
고차원의 구성 요소입니다 : 여기 내 index.js
입니다
export function requireAuthentication(Component) {
class AuthenticatedComponent extends React.Component {
componentWillMount() {
this.checkAuth();
}
componentWillReceiveProps(nextProps) {
this.checkAuth();
}
checkAuth() {
if (!this.props.isAuthenticated) {
this.props.dispatch(pushState(null, '/setup/details', ''));
}
}
render() {
return (
<div>
{this.props.isAuthenticated === true
? <Component {...this.props}/>
: null
}
</div>
)
}
}
const mapStateToProps = (state) => ({
isAuthenticated: state.get('user').get('isAuthenticated')
});
return connect(mapStateToProps)(AuthenticatedComponent);
}
내가 연령대에 이것에 대해 놀았 던을 내가 리디렉션 구성 요소를 얻을 수 없다 . Redux dev 도구에서 나는 @@reduxReactRouter/historyAPI
액션이 해고되었음을 알 수 있지만, URL은 변하지 않습니다. 모든 관련 소도구/주 등이 너무 자리에있는 것처럼 보입니다 ... 내가 놓친 부분이 있습니까?
감사
이 건너 오는 사람들을위한