useNavigate outside Router React Origin: On your device OSI layer 7 · Application Last updated 15 Oct 2026

Error: useNavigate() may be used only in the context of a <Router> component.

A React Router hook ran in a component that isn’t rendered inside a Router provider.

Exact message you may see may be used only in the context of a <Router> componentuseNavigate() may be used onlyuseLocation() may be used only
Seen on: React

Meaning

Hooks like useNavigate, useLocation and useParams need router context. Components rendered outside <BrowserRouter>/<RouterProvider> (or in tests without a MemoryRouter) fail.

Common causes

  • Router placed below the component using the hook
  • App component using hooks outside its own BrowserRouter
  • Tests rendering without a router

⚡ Quick fix

  1. Wrap the app with <BrowserRouter> at the root (index.jsx)
  2. In tests, render inside <MemoryRouter>

Detailed fix by platform

React

  1. render(<MemoryRouter><Profile /></MemoryRouter>);

How to diagnose

  1. Tree — Is the component under the Router?
  2. Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Adjacent JSX elements — Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>? (React)Adjacent JSX elementscreateContext only works in Client Components — Next.js: You're importing a component that needs createContext. It only works in a Client Component but none of its parents are marked with "use client" (Next.js)createContext only wo…Flask app context — RuntimeError: Working outside of application context. (Python)Flask app contextNo QueryClient set — Error: No QueryClient set, use QueryClientProvider to set one (React)No QueryClient setNo routes matched — No routes matched location "/x" (React)No routes matchednot wrapped in act — Warning: An update to Component inside a test was not wrapped in act(...) (React)not wrapped in actsetState during render — Warning: Cannot update a component (`Parent`) while rendering a different component (`Child`) (React)setState during renderuseContext undefined — TypeError: Cannot destructure property 'user' of 'useContext(...)' as it is undefined. (React)useContext undefineduseNaviga…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.