Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

When to use react router and react dom?


Asked by Valentino McKenzie on Dec 10, 2021 React



The first one, react-router is the core package and is used with the next two packages listed above. The react-router-dom has to be used when building a web application. This is what we are going to use in this tutorial.
In addition,
react-router-dom: It is used for web applications design. It is not possible to install react-router directly in your application. To use react routing, first, you need to install react-router-dom modules in your application. The below command is used to install react router dom.
Consequently, react-router-dom is used to do the route in react. react-router-dom provides switch and Link which are very useful to route the components In react.
Keeping this in consideration,
First we need to import the react-router-dom into the App.js file by using import statement. import { Route , BrowserRouter } from 'react-router-dom' Then we have to import all the components which are need to be add in the Router tag.
Besides,
Now visit the below url by running npm start , you will see the output like that: You can install React Router from the public npm registry with either npm or yarn . Having installed the package, let’s come to the App.js component and import some components from react-router-dom.