Suppose we have this situation:
<Routes>
<Route path="/" element={<Master/>}/>
<Route path="/login" element={<Auth/>}>
<Route path="" element={<AuthInitiate/>}/>
<Route path="callback" element={<AuthCallback/>}/>
</Route>
</Routes>
Suppose we currently are in /login/callback
. Inside the AuthCallback
component I use:
const navigate = useNavigate()
navigate("/")
The result is that i get redirected to /login
, so I understand that the "/"
refers to the relative subroute we are in (that is, /login
). This is super useful in a lot of situations, but here I just to redirect with respect to the absolute path, so "/"
should mean exactly /
and not /login
.
How should I do?
Be aware I'm referring to the new React Router v6.
EDIT: I had something else redirecting the route, the code instead works exactly as expected and navigate("/")
from subroute indeed navigate to root level. There are no issues with navigation from subroutes, sorry.