Ich habe eine hohe Auftragskomponente dass Umleitungen Benutzer Armaturenbrett auf der Unterzeichnung. Das Problem ist, das Armaturenbrett ist nicht neu auf Umleitung gemacht zu werden.
static getDerivedStateFromProps(nextProps) {
if (nextProps.user.isAuthenticated) {
nextProps.history.push(/dashboard);
}
if (nextProps.errors) {
return { errors: nextProps.errors };
}
return null;
}
Würde jemand wissen, was das Problem sein könnte? Ich bin mit Hash-Router von der Art und Weise
IsAuthenticated (FullCode)
import React, { Component } from react;
import { connect } from react-redux;
import { initLogin } from ../../actions/userActions;
export interface authHocProps {
user?: any;
history?: any;
initLogin: () => void;
}
export interface authState {
errors: object;
}
export default function(WrappedComponent) {
class IsAuth extends Component<authHocProps, authState> {
// this line is magic, redirects to the dashboard after user signs up
// this replace getDerivedStateFromPropss
static getDerivedStateFromProps(nextProps) {
if (nextProps.user.isAuthenticated) {
nextProps.history.push(/dashboard);
}
if (nextProps.errors) {
return { errors: nextProps.errors };
}
return null;
}
ourState: authState = {
errors: {},
};
componentDidMount() {
this.props.initLogin();
if (this.props.user.isAuthenticated) {
this.props.history.push(/dashboard);
}
}
render() {
return <WrappedComponent {...this.props} />;
}
}
const mapStateToProps = (state: any) => ({
user: state.user,
});
const mapDispatchToProps = (dispatch: any) => ({
initLogin: () => dispatch(initLogin()),
});
return connect(mapStateToProps, mapDispatchToProps)(IsAuth);
}