Using the Router

Once we have installed the React Router package in our environment, we need to use the provided components in our application.

The first thing we need to do is add routing capabilities to our application. We can do this by changing the code of the index.js file, as follows:

import React from 'react';
...
import { BrowserRouter } from 'react-router-dom'

ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>
, document.getElementById('root'));
registerServiceWorker();

We highlighted the main differences, with respect to the previous version of the code. As you can see, we imported the BrowserRouter component from the react-router-dom module and wrapped the App component inside of it.

By wrapping the App component, the BrowserRouter component enriches it with routing capabilities.


This is a component composition hence we have called this as component wrapping.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.14.118