React redirection problem?

beginners. I redirect to another component in one component

 constructor(props: any) {
        super(props);
        this.props.history.push("/auth_manage")
    };
The

redirection is successful, but the rest of the component"s functions (render ()) and the like are executed, so how do you jump out of this component directly here?

Mar.31,2022

in fact, this has misunderstood the idea of react-router. If you want to jump to another route after matching one route, you should use:

<Redirect from="" to=""/>

you should not jump after entering the route. If you enter the route and need to determine that certain conditions are met before you jump, and you must enter this page, then you need to write this in render or DidMount, because the execution of render cannot be prevented during initialization. You can write this in render

.
render() {
    if (xxxx) {
        this.props.history.push('/auth_manage');
        return '';
    }
    return 'xxxxx';
}

intuition tells me that it is return;


General overall large solution using routing
fundamentals using dynamic import
complete js package solution can use react-loadable, dynamic load build

Menu