1)We need to install react-route-dom, see the step to install this in below installation link. REACT_ROUTE_DOM_Installation
2)Develop below component to see the routing flow
- /src/pages/Home.js
- /src/pages/Rooms.js
- /src/pages/SingleRoom.js-This is class component
3)Update App.js as below
4)Update Index component of your project as below
npm start
6)Browse as below see the impact of routing to pages
http://localhost:3000/
http://localhost:3000/rooms
http://localhost:3000/singleroom
Requirement: Suppose there is no match of url then render the error page
Implementation:
To do so, we need to create use Switch and Route class.
1)Create one Error component as below
- /src/pages/Error.js
2)Update App.js as below