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:03,460
So let's solve this error
2
00:00:03,460 --> 00:00:06,420
with the getStaticPaths function.
3
00:00:06,420 --> 00:00:09,720
For this in our pid.js file,
4
00:00:09,720 --> 00:00:12,480
I simply export another function.
5
00:00:12,480 --> 00:00:17,210
Another async function called getStaticPaths.
6
00:00:17,210 --> 00:00:19,300
And just like getStaticProps,
7
00:00:19,300 --> 00:00:22,440
you must make sure that you have no typo in there
8
00:00:22,440 --> 00:00:26,113
because Next.js will look for this function specifically.
9
00:00:27,140 --> 00:00:29,550
Now the goal of this function
10
00:00:29,550 --> 00:00:34,550
is to tell Next.js which instances of this dynamic page
11
00:00:35,140 --> 00:00:37,090
should be generated.
12
00:00:37,090 --> 00:00:40,000
Therefore, this should return an object,
13
00:00:40,000 --> 00:00:42,420
just as getStaticProps does,
14
00:00:42,420 --> 00:00:45,790
but an object with different kinds of values.
15
00:00:45,790 --> 00:00:49,130
An object where you have a paths key.
16
00:00:49,130 --> 00:00:53,510
And that's now an array, an array full of objects.
17
00:00:53,510 --> 00:00:57,620
So that is a given structure, which you must return here.
18
00:00:57,620 --> 00:01:01,740
Now in this object, you must add a params key now,
19
00:01:01,740 --> 00:01:03,530
and that holds another object
20
00:01:03,530 --> 00:01:06,470
where you have a bunch of key value pairs
21
00:01:06,470 --> 00:01:08,700
where the keys are all the different
22
00:01:08,700 --> 00:01:12,670
dynamic segment identifiers that might lead to this page.
23
00:01:12,670 --> 00:01:15,450
If that would be nested deeper in a folder
24
00:01:15,450 --> 00:01:17,370
where the folder name is also dynamic,
25
00:01:17,370 --> 00:01:20,360
you could have multiple identifiers.
26
00:01:20,360 --> 00:01:21,540
Here it's only one.
27
00:01:21,540 --> 00:01:25,360
So pid, and the values are then the concrete values
28
00:01:25,360 --> 00:01:27,483
for which this page should be generated.
29
00:01:28,320 --> 00:01:29,440
So here, for example,
30
00:01:29,440 --> 00:01:33,130
we know that we want to generate this page three times
31
00:01:33,130 --> 00:01:35,750
for p one, p two, and p three
32
00:01:35,750 --> 00:01:40,050
as values for this dynamic page identifier here.
33
00:01:40,050 --> 00:01:43,750
And therefore I'll set pid here to p one.
34
00:01:43,750 --> 00:01:46,530
And then I will repeat that.
35
00:01:46,530 --> 00:01:49,770
So now we just create another object
36
00:01:49,770 --> 00:01:54,213
where params is set to another object with pid p two.
37
00:01:55,250 --> 00:01:58,873
And we now repeat this a third time here.
38
00:02:00,130 --> 00:02:03,010
So another object where params is then set
39
00:02:03,010 --> 00:02:06,913
to p three, like this.
40
00:02:08,250 --> 00:02:13,250
Now this tells Next.js that this dynamic page here
41
00:02:13,290 --> 00:02:18,290
should be pre-generated three times with these three values
42
00:02:18,730 --> 00:02:22,023
as a value for this dynamic segment identifier.
43
00:02:22,920 --> 00:02:27,190
And then Next.js will call getStaticProps three times
44
00:02:27,190 --> 00:02:29,010
for these different ideas.
45
00:02:29,010 --> 00:02:32,210
And we then can extract that ID like this
46
00:02:32,210 --> 00:02:33,743
inside of this function.
47
00:02:34,740 --> 00:02:35,730
Now for this to work,
48
00:02:35,730 --> 00:02:39,550
we also need to add another key next to paths,
49
00:02:39,550 --> 00:02:41,980
and that's the fallback key,
50
00:02:41,980 --> 00:02:45,370
which for the moment should be set to false.
51
00:02:45,370 --> 00:02:46,790
I'll come back to that later.
52
00:02:46,790 --> 00:02:48,390
For the moment, set it to false.
53
00:02:48,390 --> 00:02:51,910
And then if you save everything, you will see
54
00:02:51,910 --> 00:02:55,290
that if you will load local host 3000 slash p two,
55
00:02:55,290 --> 00:02:58,630
for example, you have the Product Two page.
56
00:02:58,630 --> 00:03:00,270
If I go back to the starting page
57
00:03:00,270 --> 00:03:02,020
and I click on product three,
58
00:03:02,020 --> 00:03:04,720
I have product three data here.
59
00:03:04,720 --> 00:03:08,430
And now that is displayed correctly and successfully
60
00:03:08,430 --> 00:03:13,430
because it was pre-generated successfully by Next.js.
61
00:03:13,670 --> 00:03:16,700
And therefore getStaticPaths is required
62
00:03:16,700 --> 00:03:20,880
to tell Next.js which concrete instances
63
00:03:20,880 --> 00:03:24,513
of this dynamic page must be pre-generated.
4921
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.