reacttraining.com guides Flashcards
How do you install React Router?
npm install react-router-dom
What are the three primary categories of components in React Router?
routers
route matchers
navigation
What are examples of router components in React Router?
< BrowserRouter > and < HashRouter >
What are examples of route matcher components in React Router?
< Route > and < Switch >
What are examples of navigation components in React Router?
< Link >, < NavLink >, and < Redirect >
How can navigation components be thought of?
As route changers.
Where should all the components that you use in a web application be imported from?
react-router-dom.
What is the core of every React Router application?
A router component.
What’s the main difference in the way < BrowserRouter > and < HashRouter > store URL’s?
A < BrowserRouter > uses regular URL paths. These are generally the best-looking URLs.
A < HashRouter > stores the current location in the hash portion of the URL, so the URL looks something like http://example.com/#/your/page.
What is a potential downside of using < BrowserRouter > in regards to the server?
They require your server to be configured correctly. Specifically, your web server needs to serve the same page at all URLs that are managed client-side by React Router. Create React App supports this out of the box in development, and comes with instructions on how to configure your production server as well.
What is a potential advantage of using < HashRouter > in regards to the server?
Since the hash is never sent to the server, no special server configuration is needed.
How do you use a router?
Just make sure it is rendered at the root of your element hierarchy. Typically you’ll wrap your top-level element in a router.
What are the two route matching components?
Switch and Route.
What happens when a < Switch > is rendered?
It searches through its children < Route > elements to find one whose path matches the current URL.
What happens when a < Switch > finds a path matching the current URL?
It renders that < Route > and ignores all others. This means that you should put < Route >s with more specific (typically longer) paths before less-specific ones.