मुझे लगता है कि रीडायरेक्ट उपयोगकर्ता साइन इन करने पर डैशबोर्ड पर एक उच्च आदेश घटक है। इस मुद्दे को फिर से डैशबोर्ड रीडायरेक्ट पर गाया नहीं जा रहा है।
static getDerivedStateFromProps(nextProps) {
if (nextProps.user.isAuthenticated) {
nextProps.history.push(/dashboard);
}
if (nextProps.errors) {
return { errors: nextProps.errors };
}
return null;
}
चाहेंगे किसी को क्या समस्या हो सकती है पता है? मैं जिस तरह से हैश रूटर उपयोग कर रहा हूँ
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);
}