How to use useNavigate to transition from a button in React

Introduction

react-router-dom’s useNavigate is a useful tool for implementing page transitions in React.

It’s often used in cases like “navigating to another page when a button is pressed” or “dynamically switching pages using an input ID.”…


This content originally appeared on DEV Community and was authored by Kazutora Hattori

Introduction

react-router-dom's useNavigate is a useful tool for implementing page transitions in React.

It's often used in cases like "navigating to another page when a button is pressed" or "dynamically switching pages using an input ID."

This article clearly explains the basic usage of navigate and how to combine it with forms and input values.

Preparation

1.First, obtain the function with useNavigate.

import { useNavigate } from "react-router-dom";

const navigate = useNavigate();

2.Navigate to a fixed page

To navigate to a specific route, simply pass a string.

navigate("/cards/register"); // Navigate to the new registration page

3.Passing values ​​dynamically

Using template literals, you can embed input values ​​in the URL.

const onSubmit = (data: any) => {
navigate(`/cards/${data.userId}`);
// Example: If userId is "hello", navigate to /cards/hello
};

Summary

  • useNavigate → Get the function

  • navigate("/path") → Navigate to the page

  • navigate(/cards/${data.userId}) → Dynamically navigate using the input value


This content originally appeared on DEV Community and was authored by Kazutora Hattori


Print Share Comment Cite Upload Translate Updates
APA

Kazutora Hattori | Sciencx (2025-09-27T08:39:45+00:00) How to use useNavigate to transition from a button in React. Retrieved from https://www.scien.cx/2025/09/27/how-to-use-usenavigate-to-transition-from-a-button-in-react/

MLA
" » How to use useNavigate to transition from a button in React." Kazutora Hattori | Sciencx - Saturday September 27, 2025, https://www.scien.cx/2025/09/27/how-to-use-usenavigate-to-transition-from-a-button-in-react/
HARVARD
Kazutora Hattori | Sciencx Saturday September 27, 2025 » How to use useNavigate to transition from a button in React., viewed ,<https://www.scien.cx/2025/09/27/how-to-use-usenavigate-to-transition-from-a-button-in-react/>
VANCOUVER
Kazutora Hattori | Sciencx - » How to use useNavigate to transition from a button in React. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/27/how-to-use-usenavigate-to-transition-from-a-button-in-react/
CHICAGO
" » How to use useNavigate to transition from a button in React." Kazutora Hattori | Sciencx - Accessed . https://www.scien.cx/2025/09/27/how-to-use-usenavigate-to-transition-from-a-button-in-react/
IEEE
" » How to use useNavigate to transition from a button in React." Kazutora Hattori | Sciencx [Online]. Available: https://www.scien.cx/2025/09/27/how-to-use-usenavigate-to-transition-from-a-button-in-react/. [Accessed: ]
rf:citation
» How to use useNavigate to transition from a button in React | Kazutora Hattori | Sciencx | https://www.scien.cx/2025/09/27/how-to-use-usenavigate-to-transition-from-a-button-in-react/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.