React Router: 'useNavigate() may be used only in the context of a <Router> component'
@devsingh05▲ 10 net votes
The component calling useNavigate, useLocation or useParams is rendered outside the router. Wrap the app root: <BrowserRouter><App /></BrowserRouter> in main.jsx (or use createBrowserRouter with RouterProvider), and make sure the hook is not called in the same component that renders the BrowserRouter. In tests, wrap the component in <MemoryRouter>.