---
title: "Discussion on \"How to fix the \"useNavigate() may be used only in the context of a <Router> component\" error in React\" | Hashnode"
description: "Discussion on \"How to fix the \"useNavigate() may be used only in the context of a <Router> component\" error in React\". I recently came across this error while trying to do programmatic navigation in React and wanted to write this down for my future self, in case I run into this again.\nUsually, you will want to use the useNavigate() hook instead of useHistory in the l..."
url: "https://hashnode.com/posts/how-to-fix-the-usenavigate-may-be-used-only-in-the-context-of-a-router-component-error-in-react/63485a596c2a020b48c4a2bb"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to fix the "useNavigate() may be used only in the context of a <Router> component" error in React](https://codechunks.hashnode.dev/how-to-fix-the-usenavigate-may-be-used-only-in-the-context-of-a-router-component-error-in-react?utm_source=hashnode&utm_medium=feed)

I recently came across this error while trying to do programmatic navigation in React and wanted to write this down for my future self, in case I run into this again. Usually, you will want to use the useNavigate() hook instead of useHistory in the l...

Oct 13, 2022 · 1 min read · codechunks.hashnode.dev  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#react-router](https://hashnode.com/tag/react-router)

## Written by

[Debbie Otuagomah](https://hashnode.com/@thatgirldorian)

@thatgirldorian

  
[View profile](https://hashnode.com/@thatgirldorian)

Frontend Developer

Hi! I'm Debbie and I'm currently building an array of frontend engineering skills by learning in public. Here's where I write helpful notes about everything JavaScript for my future self.

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
