Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,040 --> 00:00:04,680
Now, the last feature I want to cover here
2
00:00:04,680 --> 00:00:09,060
before we dive into the demo project is redirects,
3
00:00:09,060 --> 00:00:12,410
a feature that allows us to redirect the user.
4
00:00:12,410 --> 00:00:14,760
And I got an example for this as well.
5
00:00:14,760 --> 00:00:17,290
In our App.js file, we defined routes
6
00:00:17,290 --> 00:00:22,090
for /welcome, /products and /products/productId.
7
00:00:22,090 --> 00:00:27,090
Now, what if I just visit my domain /nothing
8
00:00:27,380 --> 00:00:29,500
then I don't get an error,
9
00:00:29,500 --> 00:00:32,830
but I also don't see anything on the screen.
10
00:00:32,830 --> 00:00:35,040
Now, here, we might want to redirect
11
00:00:35,040 --> 00:00:37,420
the user to /welcome.
12
00:00:37,420 --> 00:00:39,010
Of course, we could always adjust
13
00:00:39,010 --> 00:00:41,750
change this to /nothing exact here
14
00:00:41,750 --> 00:00:44,650
and showed a welcome page for /nothing.
15
00:00:44,650 --> 00:00:46,360
But if that's not what we want
16
00:00:46,360 --> 00:00:48,500
we can redirect and stat.
17
00:00:48,500 --> 00:00:51,470
For this, we can to find another route
18
00:00:51,470 --> 00:00:56,470
where the path is /nothing and where we add exact so
19
00:00:56,770 --> 00:01:00,550
that this is not treated as the start of a route.
20
00:01:00,550 --> 00:01:02,730
Otherwise it would match all routes
21
00:01:02,730 --> 00:01:06,810
because all the routes start with /nothing in the end.
22
00:01:06,810 --> 00:01:08,740
Hence, we need exact here.
23
00:01:08,740 --> 00:01:13,540
And then inside of this route, I don't render J as X code.
24
00:01:13,540 --> 00:01:16,300
I don't render another of custom component.
25
00:01:16,300 --> 00:01:18,900
Instead, we render a component provided
26
00:01:18,900 --> 00:01:21,150
by React router Dom.
27
00:01:21,150 --> 00:01:23,423
The redirect component.
28
00:01:24,320 --> 00:01:27,480
That is a component, which you can render like this.
29
00:01:27,480 --> 00:01:31,380
And if it gets rendered, it will do what the name implies.
30
00:01:31,380 --> 00:01:34,410
It redirects the user somewhere else.
31
00:01:34,410 --> 00:01:38,510
So here we can then redirect to /welcome,
32
00:01:39,930 --> 00:01:42,970
which means if we're just visiting /nothing,
33
00:01:42,970 --> 00:01:44,500
this will be rendered
34
00:01:44,500 --> 00:01:48,320
and this will then change the URL to /welcome.
35
00:01:48,320 --> 00:01:51,110
And then this route will become active.
36
00:01:51,110 --> 00:01:54,840
Hence exact is very important here because without it
37
00:01:54,840 --> 00:01:56,940
every route would be matched here
38
00:01:56,940 --> 00:01:59,200
and we would be redirecting all the time
39
00:01:59,200 --> 00:02:01,070
and we would create an infinite loop there
40
00:02:01,070 --> 00:02:03,403
for so exact matters.
41
00:02:04,460 --> 00:02:06,410
But with that, if we save this
42
00:02:06,410 --> 00:02:09,000
if I visit just my domain /nothing
43
00:02:09,000 --> 00:02:13,040
you see it automatically changes to /welcome
44
00:02:13,040 --> 00:02:15,120
in the URL here.
45
00:02:15,120 --> 00:02:17,580
And that's how we can use redirects
46
00:02:17,580 --> 00:02:19,540
in our application with help
47
00:02:19,540 --> 00:02:23,123
of this redirect component provided by react router.
3620
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.