Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,390 --> 00:00:03,120
OK, so what is routing?
2
00:00:04,010 --> 00:00:11,450
Well, right now, we only have one homepage component that pretty much comprises our entire app.
3
00:00:12,360 --> 00:00:20,250
But what if we had multiple page components, like an about page or a shot page or a Check-Out page
4
00:00:20,760 --> 00:00:25,800
that needed to be rendered depending on what you URL the user was at?
5
00:00:26,720 --> 00:00:34,010
Well, that is what Routings seeks to solve, and the routing library we're going to use is called React
6
00:00:34,010 --> 00:00:34,840
Router Dom.
7
00:00:35,660 --> 00:00:41,810
Now there are other routing libraries out there for react but react router Dom is the most popular and
8
00:00:41,810 --> 00:00:44,300
most supported library for routing.
9
00:00:44,300 --> 00:00:51,230
When it comes to building our application and react, it's easy to understand and it follows are component
10
00:00:51,230 --> 00:00:52,300
driven architecture.
11
00:00:53,120 --> 00:00:55,520
So let's actually try it out.
12
00:00:56,240 --> 00:00:57,290
So how do we use it?
13
00:00:57,740 --> 00:01:05,870
Well, first we have to install Riak Rotterdam and what I'm going to do is I am going to kill our server
14
00:01:06,770 --> 00:01:09,590
and I'm going to yawn and react.
15
00:01:09,590 --> 00:01:10,330
Router Dom.
16
00:01:12,290 --> 00:01:18,500
Now, there is a chance that our libraries for battle just will conflict again, like it did when we
17
00:01:18,500 --> 00:01:23,870
first installed Node SACE, and if it does, I'm going to show you how we can fix that issue.
18
00:01:24,950 --> 00:01:26,330
So if Iranians start.
19
00:01:27,540 --> 00:01:29,250
Yes, so we see that that's an issue.
20
00:01:29,880 --> 00:01:31,470
OK, that's fine.
21
00:01:32,190 --> 00:01:38,040
The reason for this is because there are dependencies between the Riak scripts that's in our Create
22
00:01:38,040 --> 00:01:39,450
React app for Apple.
23
00:01:39,450 --> 00:01:48,030
Just that is different from the one that is being required from some other version of a library that
24
00:01:48,030 --> 00:01:48,660
we installed.
25
00:01:48,810 --> 00:01:49,190
Right.
26
00:01:49,770 --> 00:01:54,870
But this is OK because it looks like the major versions are not in conflict.
27
00:01:54,880 --> 00:01:56,240
It's just this minor.
28
00:01:56,280 --> 00:01:57,780
It's the seven versus the eight.
29
00:01:57,810 --> 00:02:06,960
So what we can do with yarn is inside of our package, JSON, we can add a resolution.
30
00:02:10,500 --> 00:02:16,020
And we can tell it that we want be able just to always be twenty four point seven point one no matter
31
00:02:16,020 --> 00:02:16,230
what.
32
00:02:17,040 --> 00:02:26,040
So now if we re install all of our dependencies, we'll see that we're forcing Bable just to be twenty
33
00:02:26,040 --> 00:02:27,270
four point seven point one.
34
00:02:28,140 --> 00:02:28,950
And now.
35
00:02:30,130 --> 00:02:32,830
We should have no problem starting our application.
36
00:02:34,620 --> 00:02:35,100
Awesome.
37
00:02:35,130 --> 00:02:36,750
OK, so.
38
00:02:37,950 --> 00:02:41,130
Let's actually see how to use react router dom.
39
00:02:42,180 --> 00:02:49,290
Well, first, we have to go to our next guests and we have to import in browser router.
40
00:02:50,370 --> 00:02:52,650
From React router dom.
41
00:02:54,170 --> 00:02:59,510
And browser router is a component that we're actually going to wrap around our application.
42
00:03:01,360 --> 00:03:08,830
And what this component does is it gives our application that's sitting between this component, all
43
00:03:08,830 --> 00:03:13,090
of the functionality of routing that this library provides.
44
00:03:14,120 --> 00:03:24,680
Now, in order for me to show you what react router does, I'm just going to write a bit of code first,
45
00:03:24,950 --> 00:03:27,590
because it'll make more sense if you see it.
46
00:03:29,120 --> 00:03:38,720
So I'm going to import this component route from Rotterdam and then I'm just going to make a quick component.
47
00:03:39,690 --> 00:03:44,700
That renders out a div with an H1.
48
00:03:45,960 --> 00:03:47,520
Of Hats page.
49
00:03:48,470 --> 00:03:53,420
And this is just going to represent another page turn to our homepage right now called Arhats Page.
50
00:03:54,820 --> 00:03:57,580
So how this root component works.
51
00:03:59,210 --> 00:04:08,750
Is that it's a component that takes a couple of arguments, the main ones that I want to focus on are
52
00:04:08,780 --> 00:04:09,560
exact.
53
00:04:11,010 --> 00:04:13,020
Path and component.
54
00:04:14,300 --> 00:04:22,070
Now, component will be the component that we want to render, right, we want the root to render.
55
00:04:22,100 --> 00:04:24,020
So for now, let's just use homepage.
56
00:04:24,740 --> 00:04:33,170
The path will be a string that's equal to the path itself from the current place in orat.
57
00:04:33,170 --> 00:04:35,300
So because we're at the very base of our application.
58
00:04:35,300 --> 00:04:35,570
Right.
59
00:04:35,570 --> 00:04:43,550
The Yooralla is going to when we put the base, you are all is just logo's three thousand or like are
60
00:04:43,550 --> 00:04:47,900
you out without any additional sub URLs following our URL?
61
00:04:48,800 --> 00:04:56,240
So what this means is that when the Eurail is at the base, right, just slash, then I want to render
62
00:04:56,240 --> 00:04:58,370
the home page when we're at localhost.
63
00:04:58,580 --> 00:05:00,050
I just want to run to the homepage.
64
00:05:00,830 --> 00:05:04,990
Exact is a true or false property.
65
00:05:05,090 --> 00:05:06,810
So we are the past, true or false.
66
00:05:07,610 --> 00:05:12,080
And if you just keep it as this with no equals, then it's equal to true.
67
00:05:12,710 --> 00:05:19,630
It means that this path must be exactly slash in order for this component to render our home page component
68
00:05:19,640 --> 00:05:28,850
or render if the root, for example, without exact let's say the URL was localhost three thousand.
69
00:05:29,840 --> 00:05:31,000
That's right.
70
00:05:31,460 --> 00:05:34,460
It is technically still true.
71
00:05:34,460 --> 00:05:37,370
This part of the you are l right here.
72
00:05:38,380 --> 00:05:39,280
Is still true.
73
00:05:39,310 --> 00:05:41,110
So our homepage will actually still render.
74
00:05:42,230 --> 00:05:43,990
So let me show you how that would happen.
75
00:05:45,300 --> 00:05:51,510
So let's try another route where our path is hats and when it's hats, we want to render the hats page.
76
00:05:52,650 --> 00:05:54,480
Well, now, if we go to our application.
77
00:05:55,640 --> 00:05:57,380
If we navigate to hearts.
78
00:05:58,610 --> 00:06:04,700
We'll see that we have our homepage and then underneath we have our hearts page, so without the exact
79
00:06:04,880 --> 00:06:11,450
as long as the path matches, right, as long as it's present, then it will render the home page.
80
00:06:11,460 --> 00:06:13,640
But if we make sure that it's exact.
81
00:06:15,440 --> 00:06:22,430
Then now it won't render the home page unless it's exactly this path of just the slash.
82
00:06:28,140 --> 00:06:32,340
These are pretty much the main things that we need out of our root component.
83
00:06:32,370 --> 00:06:38,250
There's a couple others for more nuanced examples that we might explore later in the application.
84
00:06:38,250 --> 00:06:40,620
But most of the time, it's very easy.
85
00:06:40,620 --> 00:06:43,710
You can just go to the RACT, Dom.
86
00:06:44,720 --> 00:06:53,540
QuickStart documentation, and you can see all of the API that you have access to, but this routing
87
00:06:53,540 --> 00:06:55,550
is the main one that we're going to utilize.
88
00:06:56,930 --> 00:07:00,830
The other component I want to show is the switch component.
89
00:07:03,590 --> 00:07:10,430
Now, to use the switch component, we wrap our root components within it.
90
00:07:13,140 --> 00:07:23,790
Now, what it does is the moment that a route inside of it finds a match in the path, it does not render
91
00:07:23,790 --> 00:07:25,500
anything else but that route.
92
00:07:26,170 --> 00:07:30,870
So before when we went to our hearts, you are all right.
93
00:07:30,870 --> 00:07:36,270
If we remove the exact if we go to our hearts, you are all we know that we were matching the slash
94
00:07:36,270 --> 00:07:37,380
and the slash has.
95
00:07:37,950 --> 00:07:44,760
But switch will match first and then it will not render anything else after it.
96
00:07:46,190 --> 00:07:52,160
So if we look and we go to hats, right, we'll see that we have our homepage, but there's no hats
97
00:07:52,160 --> 00:07:55,770
page and the reason for this is because of switch.
98
00:07:55,970 --> 00:07:59,960
So the moment switch sees something match the path, right.
99
00:07:59,960 --> 00:08:02,900
As long as a route gets rendered, then it just renders that route.
100
00:08:02,900 --> 00:08:04,190
It renders nothing else.
101
00:08:04,910 --> 00:08:12,950
Now, if we put the exact back, then we will, of course, render our hats page because this homepage,
102
00:08:12,950 --> 00:08:18,130
with the exact path of forward slash, never matched at this URL of slash hats.
103
00:08:19,010 --> 00:08:22,870
And if we go back to our homepage while we're going to render our home page.
104
00:08:23,420 --> 00:08:28,160
So the switch is useful because it gives us more control over our code.
105
00:08:28,160 --> 00:08:28,520
Right.
106
00:08:28,850 --> 00:08:34,730
It allows us to kind of follow a pattern where we know that as long as one route matches, then that's
107
00:08:34,730 --> 00:08:36,100
the only thing we're going to render.
108
00:08:36,409 --> 00:08:41,840
And that's useful if we don't want to accidentally render multiple components.
109
00:08:41,840 --> 00:08:42,159
Right.
110
00:08:42,559 --> 00:08:46,600
It just a lot more control that we get from the library.
111
00:08:47,060 --> 00:08:53,030
But this switch and this root component there, the basic components that we're going to use to build
112
00:08:53,030 --> 00:08:54,380
out this application.
113
00:08:55,100 --> 00:09:00,890
And as we build, of course, we're going to pull in a little bit more and we're going to write some
114
00:09:00,890 --> 00:09:03,730
more complex code with rack router dom.
115
00:09:03,980 --> 00:09:09,740
But conceptually, this is what routing is in our project.
10603
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.