...

/

Navigation in ReactJS

Navigation in ReactJS

Learn about navigation within react-router.

Introduction to navigation

Navigation enables the user to quickly go through different pages and resources across the website. Traditionally, an anchor tag (<a>) is used to implement navigation to another page or link.

Concept of navigation in React

React is used to create single-page applications where page refresh shouldn’t be involved. This design is chosen because a page refresh clears the client state. If we use the anchor tag for navigation, clicking on the link triggers a page refresh. For this reason, we can’t use it in a React SPA to navigate between components. The react-router provides navigation interfaces that render a specific component by changing the current location.

There are two ways we can implement navigation through react-router:

1. By creating an element

The react-router provides the <Link /> and <NavLink /> components for navigation. These element show links that the users can click to navigate to specific URLs. This topic will be covered later in this lesson.

This type of navigation is used when we want the user to decide whether they want to click on a particular link or not. All the links that we use for this ...