S
SolidJS2y ago
Bravi

ProtectedRoute with a redirect using @solidjs/router

Hi everyone. Is there a way to implement a ProtectedRoute, but with a redirect using @solidjs/router? All the examples I have seen, do something like user ? <Component /> : <Login />, but the url remains the same..
2 Replies
REEEEE
REEEEE2y ago
You could make use of the Navigate component maybe https://github.com/solidjs/solid-router/tree/main#the-navigate-component Or check onMount if the user exists and call navigate from useNavigate to reroute them
Bravi
Bravi2y ago
Hey @._rb , thanks for your reply. Unfortunately this approach doesn't work, because even if I land on a different route (not the protected one), both the onMount inside a protected route and <Navigate /> are executed and therefore I'm redirected to /login