F5 refreshes the page after react login

After logging in to the react project, the F5 refresh page jumps to the login page.
how to call an API when refreshing the page to let the background check session to determine whether it is logged in?

<Router>
    <Provider store={store}>
        <Switch>
            <Route path="/login" component={Login}/>
            <PrivateRoute path="/" component={MainLayout} />
        </Switch>
    </Provider>
</Router>

where should I put this ajax request?

May.25,2021

is best judged by (express) directly in the server, and the failure is directly redirected to another page, instead of the front end loading the page and then sending a request through ajax to determine and then jump to


in the componentDidMounted of the components of that page you need to verify login. Or write a special component to do login verification, this component render () {return null}, in his componentDidMounted to verify login.

Menu