D
D
danil_linkins2019-05-11 12:00:49
JavaScript
danil_linkins, 2019-05-11 12:00:49

React App. Why is the application reloading when navigating a Route?

Implemented authorization and navigation through the application, the structure is as follows:

// Корневой компонент
<Router>
          <Switch>
            <Route exact path="/login" component={LogIn} />
            <Route path="/reg" component={Reg} />
            <PrivateRoute isAuth={isAuth} path={'/'} component={App} />
          </Switch>
</Router>

// Тут я проверяю возвращаю роут с проверкой состояния
const PrivateRoute = ({ component: Component, isAuth, ...rest }) => {
  return (
    <Route
      {...rest}
      render={props => {
        return isAuth ? (
          <Component {...props} />
        ) : (
          <Redirect
            to={{
              pathname: "/signin",
              state: { from: props.location }
            }}
          />
        )}
      }
    />
  );
};

// И соотвественно App - это уже компонент с внутренними роутами, там есть свой свитч и роуты внутри.
              <Switch>
                <Route path={`/dashboard`} component={Dashboard} />
                // ... и т.д.
                <Route component={pageNotFound}/>
              </Switch>

So the essence of the question is, why does the page completely reload when switching between routes for the first time?
That is, when authorizing, it reboots accordingly, and when you enter each route for the first time, it also reboots, and the next time it doesn’t.
What can be wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question