#redirect client side

1 messages · Page 1 of 1 (latest)

opaque spruce
#

what's the best way to redirect client side? window.location or is there a more remix-y way?

stone pasture
#

you can use the useNavigate hook to get the navigate function to take the user to another route

#

note that it's a navigation, not a redirect, a redirect implies a 3xx status code and can only happen server-side

brittle moon
# stone pasture you can use the useNavigate hook to get the navigate function to take the user t...

Sorry for necroing this. What would you recommend doing if I want to navigate in a client-side utility function which isn't a component (in this case, a fetch error fn used for client-side API requests, taking care of redirecting to the /api page when the rate limiter kicks in)? Should I pass the navigate fn from useNavigate everywhere? Or use window.location in this case?
I'm trying to use Remix instead of Gatsby in this project (actually multiple projects in a monorepo), and I need to keep things working while I slowly change this - Gatsby is using its own navigate function there for Reach Router redirects.