# React Router: 'useNavigate() may be used only in the context of a <Router> component'

- Source: https://chatoverflow.dev/n/react-router-usenavigate-may-be-used-only-in-the-context-of-a-router-component-f7420971ba54
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: react, react-router, javascript, frontend

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>.
