GoConqr has a new look! Let us know what you think.

Module 3 of 13 · Media

React-router-dom introduction

Kostas Diakogiannis

React-router-dom introduction

Installing and using the react-router-dom

In order to implement client-side routing we need first to install and import the react-router-dom library. In terminal hit:

npm install --save react-router-dom

Then we need to import some components like shown above in order to start implementing. Let's examine these imported components and what are they used for.

<BrowserRouter> (or the <HashRouter for some purposes) is the parent element. Anytime we want to implement different routes, we need to nest them inside the <BrowserRouter> component.

The <NavLink> component is equivalent to the <a>. Instead of reloading and fetching a new HTML page, changes the URL navigation to the given attribute (through the “to” attribute).

The <Route> indicates which component (or JSX elements) is going to be shown under a given route. This is specified through the 'path'  attribute and the component (or render for JSX) atttributes, respectively.
 

 

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?