reacttraining.com guides Flashcards

1
Q

How do you install React Router?

A

npm install react-router-dom

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the three primary categories of components in React Router?

A

routers
route matchers
navigation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are examples of router components in React Router?

A

< BrowserRouter > and < HashRouter >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are examples of route matcher components in React Router?

A

< Route > and < Switch >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are examples of navigation components in React Router?

A

< Link >, < NavLink >, and < Redirect >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can navigation components be thought of?

A

As route changers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Where should all the components that you use in a web application be imported from?

A

react-router-dom.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the core of every React Router application?

A

A router component.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s the main difference in the way < BrowserRouter > and < HashRouter > store URL’s?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a potential downside of using < BrowserRouter > in regards to the server?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a potential advantage of using < HashRouter > in regards to the server?

A

Since the hash is never sent to the server, no special server configuration is needed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you use a router?

A

Just make sure it is rendered at the root of your element hierarchy. Typically you’ll wrap your top-level element in a router.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the two route matching components?

A

Switch and Route.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens when a < Switch > is rendered?

A

It searches through its children < Route > elements to find one whose path matches the current URL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happens when a < Switch > finds a path matching the current URL?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What happens if no < Route > matches are found?

A

The < Switch > renders nothing (null).

17
Q

What is important to note regarding < Route path > matches?

A

That a < Route path > matches the beginning of the URL, not the whole thing. So a < Route path=”/” > will always match the URL. Because of this, we typically put this < Route > last in our < Switch >. Another possible solution is to use < Route exact path=”/” > which does match the entire URL.

18
Q

Split last question

A

qw

19
Q

What is the React Router < Link > component used for?

A

To create links in your application.

20
Q

What happens wherever you render a < Link > component?

A

An anchor (< a >) will be rendered in your HTML document.

21
Q

What is the < NavLink > component?

A

A special type of < Link >.

22
Q

What can the < NavLink > component do?

A

Style itself as “active” when its to prop matches the current location.

23
Q

What do you do if you want to force navigation?

A

Render a < Redirect >.

24
Q

When happens when a < Redirect > renders?

A

It will navigate using its to prop.

25
Q

Give a simple example of using a < NavLink > component.

A
< Link to="/" >Home< /Link >
// < a href="/" >Home< /a >
< NavLink to="/react" activeClassName="hurray" >
  React
< /NavLink >
// When the URL is /react, this renders:
// < a href="/react" className="hurray" >React< /a >
// When it's something else:
// < a href="/react" >React< /a >
< Redirect to="/login" / >
26
Q

Why is rendering on the server is a bit different than on the front end?

A

Because the server is all stateless.

27
Q

What is the basic idea of React Router rendering on the server??

A

We wrap the app in a stateless < StaticRouter > instead of a < BrowserRouter >. We pass in the requested url from the server so the routes can match and a context prop.

28
Q

What happens when you render a < Redirect > on the client?

A

The browser history changes state and we get the new screen.

29
Q

Are you able to change the apps state in a static server environment?

A

No.