React Router Rendre des pages vierges pour tous les composants
<Switch>
<Route
path="/login"
render={props => !isAuthenticated
? (
<Login setAuth={setAuth} {...props} />
) : (
<Redirect to="/dashboard" />
)
}
/>
<Route
path="/register"
render={props => !isAuthenticated
? (
<Register setAuth={setAuth} {...props} />
) : (
<Redirect to="/dashboard" />
)
}
/>
<Route
path="/dashboard"
render={props => isAuthenticated
? (
<Dashboard setAuth={setAuth} {...props} />
) : (
<Redirect to="/login" />
)
}
/>
</Switch>
//update
const [isAuthenticated, setIsAuthenticated] = useState();
if (isAuthenticated === undefined) {
return null; // or loading spinner, etc...
}
return (
... routes & UI ...
);
SAMER SAEID