“An investment in knowledge pays the best interest.” Benjamin Franklin
In our previous post we started with creating our first react app and than we learned about some basic terminologies in react. Today we are going to focus on creating the router behaviour using react library.
Incase you want to learn about filtering in react check the github code.
In our previous post we started with creating our first react app and than we learned about some basic terminologies in react. Today we are going to focus on creating the router behaviour using react library.
Incase you want to learn about filtering in react check the github code.
Pre-requites:-
Github for React Router
npm install --save react-router-dom
Key Terms:-
1) BrowserRouter
- Import Browser router in src/index.js (Line 6 in the below code example)
- Enclose
component inside (Line 8)
1 |
import React from 'react'; |
2) Link, this component accepts the to property which directs the app to the given path.
1 |
<Link |
>Contact</Link>Link component fully renders a proper anchor tag (a) with the appropriate href, you can expect it to behave how a normal link on the web behaves.
3) Route Component, this component is a critical piece of building an application with React Router because it’s the component which is going to decide which components are rendered based on the current URL path.
1 |
<Route path="/create" |