5) Master Project: React Router and Routing Flashcards
react router mimics ___.
url functionality
what is the most supported/popular react router library?
React Router DOM
What file does the import statement for BrowserRouter component go in? what is that statement?
index.js
import { BrowserRouter } from ‘react-router-dom’;
What do you do with the Browser Router component once it has been imported?
wrapping around the app component in the index.js file.
What are the three main attributes of the Router component?
- exact: whether the path has to match exactly, default value is true
- path: the path (url) that will be trigger to rendering the component
- component: the component that we want the route to render
What is the switch component used for?
wraps around route components and only renders the first one that matches
What two main components will we be using from the routing library?
Switch and Route
What 3 props get passed into the component identified in a router component?
history
location
match
what is the match prop useful for?
accessing dynamically chaging data
What react-router-DOM component replaces the a-tag? what are its attributes? what is the drawback?
Link
to=’url’
not dynamic
What is the dynamic version of using the Link component?
using the history prop in an event triggered call back function in a regular component (like a button):
onClick={() => props.history.push(‘/topics’)}
The match prop allows our components to build out …
a nested route structure
what is prop tunneling and why is it an issue?
sending props through child components, the components in the middle wont need the props.
What is a higher order component?
a function that takes a component as an argument and returns a modified component.
how do you use the withRouter() function on a component? what features does this give that component?
in the export statement wrap the component with the function.
gives us the history property