// RequiresAuth.js
export function RequiresAuth({ children, login }) {
return login ? children : <Navigate to="/login" replace />;
}
// App.js
<Route
path="/address"
element={
<RequiresAuth login={login}>
<Address />
</RequiresAuth>
}
/>
// Routing
if you are not logged in
/address
/login /address
when you are going back
/login should not come again
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter