Topic Overview and Actualization

Welcome! Today, we'll journey through the process of programmatic navigation using React Router v6. We'll explore the hooks useNavigate and useLocation, along with a concept known as navigation with state. Let's jump in!

Navigating Programmatically

Typically, a React app that uses Router v6 utilizes Link or NavLink for navigation. However, there are instances when we require more control, such as redirecting after a form submission. That's when we turn to programmatic navigation.

The Magic of useNavigate

useNavigate hook provides a function enabling navigation in our React router application. In addition to navigating to absolute paths like /login or /home, useNavigate possesses the superpower to navigate relative to the current location. It also introduces a new way to navigate backwards.

For instance, if we wanted to move back one step in our route history, we could call . It's a simple and intuitive feature that can be incredibly handy in certain scenarios.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal