Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,160 --> 00:00:03,540
Were you successful?
2
00:00:03,540 --> 00:00:04,780
Let's do it together.
3
00:00:04,780 --> 00:00:07,050
And let's start with redirecting.
4
00:00:07,050 --> 00:00:10,690
I want to redirect from slash nothing to slash quotes,
5
00:00:10,690 --> 00:00:13,870
and for that, in my route, route definition,
6
00:00:13,870 --> 00:00:18,100
in this route component instead of this switch block here,
7
00:00:18,100 --> 00:00:19,990
I'll add another route.
8
00:00:19,990 --> 00:00:23,300
And here the path will just be slash nothing.
9
00:00:23,300 --> 00:00:25,640
We should also add the exact prop here
10
00:00:25,640 --> 00:00:28,040
so that we don't look at the beginning of the path
11
00:00:28,040 --> 00:00:30,223
but we only match full paths.
12
00:00:31,680 --> 00:00:35,050
And then here, I don't want to render a custom component
13
00:00:35,050 --> 00:00:36,350
but instead we'll render
14
00:00:36,350 --> 00:00:39,570
a component provided by React Router.
15
00:00:39,570 --> 00:00:42,190
And that's the redirect component.
16
00:00:42,190 --> 00:00:44,370
Whenever this component gets rendered,
17
00:00:44,370 --> 00:00:46,120
the browser redirects.
18
00:00:46,120 --> 00:00:49,840
So it loads a different URL, a different path.
19
00:00:49,840 --> 00:00:52,440
And here inside of this first route,
20
00:00:52,440 --> 00:00:56,180
I now do want to redirect and reduce that to two prop here
21
00:00:56,180 --> 00:00:59,570
to tell React Router where to redirect.
22
00:00:59,570 --> 00:01:02,610
And I want to redirect to slash quotes here.
23
00:01:02,610 --> 00:01:06,070
So that if we visit our domain slash nothing,
24
00:01:06,070 --> 00:01:09,123
we redirect to our domain slash quotes.
25
00:01:10,120 --> 00:01:14,620
And with this, if we enter local hosts 3000, like this,
26
00:01:14,620 --> 00:01:17,343
it automatically changes to slash quotes.
27
00:01:18,260 --> 00:01:22,530
Now the other task I gave you was to extract this quote ID
28
00:01:22,530 --> 00:01:25,000
on this quote detail page.
29
00:01:25,000 --> 00:01:27,490
And we also learned how that works.
30
00:01:27,490 --> 00:01:29,660
Inside of that loaded component,
31
00:01:29,660 --> 00:01:33,910
we can use a special hook provided by a React Router DOM.
32
00:01:33,910 --> 00:01:36,152
We can use the useParams hook
33
00:01:36,152 --> 00:01:38,960
which we import from React Router DOM,
34
00:01:38,960 --> 00:01:41,400
and then we can call useParams
35
00:01:41,400 --> 00:01:45,023
in this functional component and get access to the params.
36
00:01:46,120 --> 00:01:47,700
And then now that we got access,
37
00:01:47,700 --> 00:01:50,110
we can output the params, of course.
38
00:01:50,110 --> 00:01:52,360
We could for example, add a fragment,
39
00:01:52,360 --> 00:01:54,663
or a section or a div here.
40
00:01:55,530 --> 00:02:00,430
Of course, if you do go for a fragment as I do here,
41
00:02:00,430 --> 00:02:03,360
you need to import it from React,
42
00:02:03,360 --> 00:02:06,320
and then here, below that, we could have a paragraph
43
00:02:06,320 --> 00:02:08,646
where we simply output params.quoteID
44
00:02:09,810 --> 00:02:11,980
Now it's dot quote ID here
45
00:02:11,980 --> 00:02:16,670
because I gave my identifier a name of quoteID.
46
00:02:16,670 --> 00:02:20,217
Here after the colon, whatever you chose here,
47
00:02:20,217 --> 00:02:23,420
that's the key which you then can access
48
00:02:23,420 --> 00:02:26,323
on this params object in your component.
49
00:02:27,260 --> 00:02:29,550
And with this, if we save that,
50
00:02:29,550 --> 00:02:34,190
and I enter slash quotes, slash first dash quote,
51
00:02:34,190 --> 00:02:38,193
for example, I see first quote, down here.
52
00:02:39,720 --> 00:02:42,380
So this is now also working and with that,
53
00:02:42,380 --> 00:02:47,270
we applied almost all the things I wanted to apply.
54
00:02:47,270 --> 00:02:51,260
One thing is missing though, and that's a nested route.
55
00:02:51,260 --> 00:02:52,860
Which I wanna add.
56
00:02:52,860 --> 00:02:56,110
We currently don't have any real data which we use,
57
00:02:56,110 --> 00:02:57,660
we'll do that later,
58
00:02:57,660 --> 00:03:01,930
but I already wanna simulate that on the quote detail page
59
00:03:01,930 --> 00:03:04,760
we might have comments for that quote
60
00:03:04,760 --> 00:03:08,670
so that users can leave comments for a quote.
61
00:03:08,670 --> 00:03:10,890
Hence below that paragraph,
62
00:03:10,890 --> 00:03:14,540
I want to render this comments component.
63
00:03:14,540 --> 00:03:16,760
Now for this, we could of course embed it
64
00:03:16,760 --> 00:03:18,720
just as we always do.
65
00:03:18,720 --> 00:03:20,540
But now here's the interesting thing,
66
00:03:20,540 --> 00:03:23,270
I wanna use a nested route for this
67
00:03:23,270 --> 00:03:28,050
so that if we just visit slash quotes, slash some ID,
68
00:03:28,050 --> 00:03:30,390
we don't see the comments.
69
00:03:30,390 --> 00:03:35,040
Only if we visit slash quotes, slash some ID,
70
00:03:35,040 --> 00:03:38,600
like first quote in this case, slash comments.
71
00:03:38,600 --> 00:03:41,130
Only if we have slash comments at the end,
72
00:03:41,130 --> 00:03:43,780
only then the comments components
73
00:03:43,780 --> 00:03:46,900
should be loaded below this paragraph.
74
00:03:46,900 --> 00:03:48,710
And that there for your task.
75
00:03:48,710 --> 00:03:52,840
Render the comments by using a nested route.
76
00:03:52,840 --> 00:03:55,283
We'll do it together in the next lecture.
5950
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.