Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,020 --> 00:00:03,550
In the last lecture
2
00:00:03,550 --> 00:00:05,960
we worked on this quote detailed page
3
00:00:05,960 --> 00:00:10,960
and we made sure that if I enter an unknown quote ID here
4
00:00:11,110 --> 00:00:13,433
I get some fallback text here.
5
00:00:14,360 --> 00:00:17,190
But what if I enter a totally unknown route
6
00:00:17,190 --> 00:00:18,160
to begin with,
7
00:00:18,160 --> 00:00:20,970
something like my domain slash hello
8
00:00:21,900 --> 00:00:24,200
then we have this blank page.
9
00:00:24,200 --> 00:00:27,379
And in reality we typically instead
10
00:00:27,379 --> 00:00:29,318
when I show some 404 page
11
00:00:29,318 --> 00:00:31,767
a fallback page that tells the user
12
00:00:31,767 --> 00:00:34,070
that this page doesn't exist
13
00:00:34,070 --> 00:00:36,243
instead of just showing a blank page.
14
00:00:38,180 --> 00:00:42,080
And we can also add such a 404 page
15
00:00:42,080 --> 00:00:46,163
a not found page with react router as well.
16
00:00:47,180 --> 00:00:48,013
For this all,
17
00:00:48,013 --> 00:00:51,430
first of all, add a new page here in the pages folder.
18
00:00:51,430 --> 00:00:54,890
And that's the not found JS file.
19
00:00:54,890 --> 00:00:58,010
And in there, I'll add the, not found component
20
00:00:59,150 --> 00:01:03,400
and export this here and then there,
21
00:01:03,400 --> 00:01:07,470
I'll just return a div with a class name off centered.
22
00:01:07,470 --> 00:01:10,820
And now that's not as CSS module class name,
23
00:01:10,820 --> 00:01:13,470
but a globally defined CSS class name
24
00:01:13,470 --> 00:01:16,213
defined here in this index CSS file.
25
00:01:17,120 --> 00:01:20,770
And then this div I'll then just say, page not found.
26
00:01:20,770 --> 00:01:23,140
And of course you can change the content
27
00:01:23,140 --> 00:01:26,223
of this page and style it however you want.
28
00:01:27,420 --> 00:01:31,550
Now with that we have this not found page component to find
29
00:01:31,550 --> 00:01:32,990
but how do we now make sure
30
00:01:32,990 --> 00:01:34,200
that it is showing up if a user enters
31
00:01:34,200 --> 00:01:38,560
some unsupportive path?
32
00:01:38,560 --> 00:01:42,260
For this we can go back to all our root route definition.
33
00:01:42,260 --> 00:01:45,050
'Cause here we are defining all the routes
34
00:01:45,050 --> 00:01:47,760
our application supports.
35
00:01:47,760 --> 00:01:50,530
Now, if we go through that switch statement
36
00:01:50,530 --> 00:01:53,630
and we didn't have a single match of, for example,
37
00:01:53,630 --> 00:01:56,400
for a slash hello, we don't have a match here.
38
00:01:56,400 --> 00:01:58,980
Then we leave the switch statement without a match.
39
00:01:58,980 --> 00:02:01,163
And hence nothing shows up on the screen,
40
00:02:02,100 --> 00:02:05,810
therefore to show a fallback and not found page.
41
00:02:05,810 --> 00:02:08,919
The approach typically is that we add one route here
42
00:02:08,919 --> 00:02:13,460
at the end, which is looked at if no other route matched
43
00:02:13,460 --> 00:02:16,360
where we match all incoming requests.
44
00:02:16,360 --> 00:02:17,962
So to say.
45
00:02:17,962 --> 00:02:20,120
So where we match all URLs
46
00:02:20,120 --> 00:02:22,830
and we do that by setting the path to a star
47
00:02:23,760 --> 00:02:28,580
This wild card character signals to react router
48
00:02:28,580 --> 00:02:33,580
that any path any URL should match this route.
49
00:02:34,240 --> 00:02:37,030
And therefore this route has to come last
50
00:02:37,030 --> 00:02:39,846
so that it does not consume one of the requests
51
00:02:39,846 --> 00:02:42,363
to one of the actual routes we have.
52
00:02:43,360 --> 00:02:47,140
But if we didn't have any match up to this point
53
00:02:47,140 --> 00:02:51,190
then we want to match all URLs with this route.
54
00:02:51,190 --> 00:02:54,390
And then just rendered this not found page here.
55
00:02:54,390 --> 00:02:59,390
So here I'll now import not found from pages
56
00:03:00,190 --> 00:03:01,203
Not found.
57
00:03:02,520 --> 00:03:05,050
And output does not found component
58
00:03:05,050 --> 00:03:09,900
here in this match all route here,
59
00:03:09,900 --> 00:03:14,050
which is only considered if no other route matched.
60
00:03:14,050 --> 00:03:17,000
And with this, if I saved this for hello,
61
00:03:17,000 --> 00:03:19,730
we get this page not found text.
62
00:03:19,730 --> 00:03:20,563
On the other hand,
63
00:03:20,563 --> 00:03:22,530
if I do enter slash quotes.
64
00:03:22,530 --> 00:03:25,480
So I do visit with one of my supported pages.
65
00:03:25,480 --> 00:03:27,537
Then I see that page.
66
00:03:27,537 --> 00:03:30,720
And with this, we also added this not found page
67
00:03:30,720 --> 00:03:34,020
which of course is a never common requirement you might have
68
00:03:34,020 --> 00:03:35,483
in your applications.
5259
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.