w7d4 - react router Flashcards
What props can you pass into a Route?
path
component
exact
What’s the purpose of a Route?
A Route is used to wrap another component, causing that component to only be rendered if a certain URL is matched.
What does the exact prop do when passed in to Route?
The component will only render if that route and that route exactly matches (no params in the url, no variance from the path prop period).
What’s the parent router component called?
HashRouter
What are child route components called?
Router
What props does a Router pass to its child component?
location
match
history
What keys does the match prop contain?
isExact
url
path
params
What methods does the history prop contain? What do they do?
push - adds a new URL to the end of the history stack
replace - replaces the current URL on the history stack, so the back button won’t take you to it.
From within a Routeful component, how do we get user_id from the path?
this.props.match.params.userId
How do you use a Link component?
<link></link>
Users</Users>
Optional prop to pass to Link?
onClick
Difference between a NavLink and regular Link?
logic that automatically chooses a secondary activeClassName CSS class when its route is active.
How do you select one Route out of many to render when many Routes match the same path?
Wrap the routes in a Switch. First one that matches will be rendered.
What’s the value of using a Switch?
It will select one Route out of many to render when many Routes match the same path.
How do we redirect a user?
Redirect component
use the to=”/new_url” prop