I see in https://reactrouter.com/en/main/hooks/use-navigate at "It's usually better to use redirect in loaders and actions than this hook" So should I change useNavigate to redirect instead right ?
I see in https://reactrouter.com/en/main/hooks/use-navigate at "It's usually better to use redirect in loaders and actions than this hook" So should I change useNavigate to redirect instead right ?
So should I change useNavigate to redirect instead right?
No, not at all. Use the useNavigate hook, and returned navigate function to issue imperative navigation actions just as it's always been done/used in react-router-dom@6 since it was introduced.
react-router-dom@6.4.0 introduced many new features relying on the new router creators that add much more functionality to the behavior of the routing context, specifically the new data APIs. In this specific case it's informing you that you shouldn't try using the useNavigate hook in a loader. Loaders are functions called by the router to make some asynchronous data request for resources that are passed to the route's component. Only use redirect in the loaders, not navigate.