From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Programmatic navigation

Programmatic navigation

Hello and welcome to lesson 5. In this lesson, we are going to learn about Programmatic Navigation with UseNavigateHook. So, the question arises, why we actually need the Programmatic Navigation? At times, we need to navigate the user after an event other than the link click. Let me give you an example. Consider you have a login form. If the user is going to provide their e-mail and password and the values are incorrect, you can show the error on the same page. But if the user has provided correct values, you would like to have the user navigated to a dashboard page where the user can do the other operations. This is going to happen on a button click. It's not a simple click, so there is a piece of code that you have to execute and you have to write a programmatic statement to redirect the user. In this type of example, we can use the UseNavigate hook. React Router provides the UseNavigate hook and it allows us to control the navigation programmatically. We can use the useNavigate…

Contents