Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,130 --> 00:00:04,590
So what exactly is routing then,
2
00:00:04,590 --> 00:00:09,070
and why would we wanna add it to our React Application?
3
00:00:09,070 --> 00:00:12,550
Well, I touched on it in the last lecture already.
4
00:00:12,550 --> 00:00:16,079
At the moment all the React Apps we built in this course,
5
00:00:16,079 --> 00:00:19,840
have the disadvantage that they have the same URL
6
00:00:19,840 --> 00:00:22,960
no matter where in this app we are.
7
00:00:22,960 --> 00:00:25,690
And therefore if we wanna share a URL,
8
00:00:25,690 --> 00:00:27,490
a link to a certain feature
9
00:00:27,490 --> 00:00:29,600
of one of the websites we're building,
10
00:00:29,600 --> 00:00:33,050
we can only share a link to the starting page.
11
00:00:33,050 --> 00:00:35,100
And then users have to navigate
12
00:00:35,100 --> 00:00:37,623
to a specific feature manually.
13
00:00:38,490 --> 00:00:40,640
Now in reality, you want websites
14
00:00:40,640 --> 00:00:42,600
where you have different paths,
15
00:00:42,600 --> 00:00:47,350
and those different paths in the URL load different pages
16
00:00:47,350 --> 00:00:49,740
so that when the URL changes,
17
00:00:49,740 --> 00:00:52,310
we change the visible content of the page.
18
00:00:52,310 --> 00:00:55,670
We load different pages for different paths
19
00:00:55,670 --> 00:00:57,020
and it's then the combination
20
00:00:57,020 --> 00:01:00,020
of all those pages with their own paths
21
00:01:00,020 --> 00:01:02,560
that make up the overall website.
22
00:01:02,560 --> 00:01:04,280
That is how the web works,
23
00:01:04,280 --> 00:01:07,880
and that is how our React App should work as well.
24
00:01:07,880 --> 00:01:10,180
We have different visual elements,
25
00:01:10,180 --> 00:01:13,280
we have different pages if you wanna call it like this,
26
00:01:13,280 --> 00:01:16,560
and each page should have its own URL
27
00:01:16,560 --> 00:01:19,760
or its own path after our domain.
28
00:01:19,760 --> 00:01:22,220
And when that path changes,
29
00:01:22,220 --> 00:01:26,290
the visual content of the page should change.
30
00:01:26,290 --> 00:01:28,620
Now when we're not working with React,
31
00:01:28,620 --> 00:01:31,870
when we have a traditional Multi-Page App
32
00:01:31,870 --> 00:01:33,460
where we have some server
33
00:01:33,460 --> 00:01:37,000
which sends back different HTML files,
34
00:01:37,000 --> 00:01:39,440
we would typically build something like this
35
00:01:39,440 --> 00:01:44,240
by simply storing different HTML files on the server,
36
00:01:44,240 --> 00:01:48,130
or by generating those files dynamically on the server.
37
00:01:48,130 --> 00:01:52,460
And then for requests to different URLs,
38
00:01:52,460 --> 00:01:56,510
different HTML pages are sent back to the client
39
00:01:56,510 --> 00:02:00,400
and these pages can then be rendered by the browser.
40
00:02:00,400 --> 00:02:02,360
Now this approach works,
41
00:02:02,360 --> 00:02:04,200
but it's not the approached we used
42
00:02:04,200 --> 00:02:06,010
up to this point in the course.
43
00:02:06,010 --> 00:02:09,289
Because when we use different HTML pages,
44
00:02:09,289 --> 00:02:11,250
we don't have a Single Page App,
45
00:02:11,250 --> 00:02:14,560
and that means that whenever we change the URL,
46
00:02:14,560 --> 00:02:17,540
we leave our running client side app.
47
00:02:17,540 --> 00:02:20,090
We lose all the state there.
48
00:02:20,090 --> 00:02:23,840
We have to wait for, to request response cycle
49
00:02:23,840 --> 00:02:27,780
and we have to let the browser render this new page.
50
00:02:27,780 --> 00:02:30,400
And that's one of the reasons why we switched to React.
51
00:02:30,400 --> 00:02:33,870
We don't wanna have this traditional flow.
52
00:02:33,870 --> 00:02:37,220
Instead we wanna load a client side application
53
00:02:37,220 --> 00:02:41,050
so a JavaScript web app, which runs in the browser,
54
00:02:41,050 --> 00:02:43,680
and we wanna utilize this application
55
00:02:43,680 --> 00:02:48,000
to change what's visible on the screen with JavaScript
56
00:02:48,000 --> 00:02:51,230
so that we can provide this very instant
57
00:02:51,230 --> 00:02:53,360
reactive user experience,
58
00:02:53,360 --> 00:02:56,750
which we can do with JavaScript in the browser
59
00:02:56,750 --> 00:03:00,850
and fetching different HTML pages doesn't fit in there
60
00:03:00,850 --> 00:03:04,790
because there we leave the browser request a new page
61
00:03:04,790 --> 00:03:06,060
rendered in new page,
62
00:03:06,060 --> 00:03:08,530
and that's not this reactive experience
63
00:03:08,530 --> 00:03:10,970
which we typically wanna offer.
64
00:03:10,970 --> 00:03:13,640
So this approach doesn't work here.
65
00:03:13,640 --> 00:03:16,730
We still wanna build a single page application step.
66
00:03:16,730 --> 00:03:20,440
And now the good news is that we can do that.
67
00:03:20,440 --> 00:03:23,960
We can continue building a Single Page Application
68
00:03:23,960 --> 00:03:27,150
and we therefore only have one HTML page,
69
00:03:27,150 --> 00:03:28,680
which is initially loaded
70
00:03:28,680 --> 00:03:31,720
when a user first visits our website
71
00:03:31,720 --> 00:03:34,700
and then thereafter we have JavaScript to take over.
72
00:03:34,700 --> 00:03:36,760
But the good thing is that
73
00:03:36,760 --> 00:03:41,253
we can also take a look at the URL and manipulate the URL
74
00:03:42,140 --> 00:03:47,060
and that path after our domain with JavaScript,
75
00:03:47,060 --> 00:03:51,190
and we can deal for also write or use some client site,
76
00:03:51,190 --> 00:03:56,190
some React code, which controls the URL and which changes,
77
00:03:56,460 --> 00:04:00,530
what we see on the screen, when that URL changes
78
00:04:00,530 --> 00:04:05,530
or when a link is clicked without fetching a new HTML file.
79
00:04:06,090 --> 00:04:10,800
So we need some code that works with the URL
80
00:04:10,800 --> 00:04:14,540
that works with that path after the domain
81
00:04:14,540 --> 00:04:17,810
and THERE listens to clicks on links on our page
82
00:04:17,810 --> 00:04:20,810
to update that path into URL,
83
00:04:20,810 --> 00:04:24,020
but which then actually does not send a request
84
00:04:24,020 --> 00:04:27,060
to the server for a new HTML file,
85
00:04:27,060 --> 00:04:29,810
but in stat, this code, which we write*
86
00:04:29,810 --> 00:04:31,640
or does package which we add
87
00:04:31,640 --> 00:04:34,360
should block does browser default.
88
00:04:34,360 --> 00:04:37,720
And instead update, what's visible on the screen
89
00:04:37,720 --> 00:04:41,690
with client side JavaScript with React.
90
00:04:41,690 --> 00:04:44,970
So we want the package, which does all that routing
91
00:04:44,970 --> 00:04:46,820
and which looks at the URL
92
00:04:46,820 --> 00:04:49,060
and brings different components
93
00:04:49,060 --> 00:04:51,970
onto the screen based on URL changes.
94
00:04:51,970 --> 00:04:54,850
But which does all of that in the browser,
95
00:04:54,850 --> 00:04:57,190
we need to write code that does that
96
00:04:57,190 --> 00:05:00,830
or we use a third-party package that does that.
97
00:05:00,830 --> 00:05:03,963
And thankfully there is a third party package for that.
7751
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.