Answer the question
In order to leave comments, you need to log in
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>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question