Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,180 --> 00:00:05,170
Creating the detail page like this works,
2
00:00:05,170 --> 00:00:07,840
until we realize that we probably would have
3
00:00:07,840 --> 00:00:11,700
more than one news item on our news site.
4
00:00:11,700 --> 00:00:14,660
It would be very realistic that index.js
5
00:00:14,660 --> 00:00:18,790
and the news folder should output a list of news items.
6
00:00:18,790 --> 00:00:21,170
And then we can click those individual items
7
00:00:21,170 --> 00:00:23,410
and then take into the detailed pages
8
00:00:23,410 --> 00:00:28,410
with the concrete content for the news item we selected.
9
00:00:28,440 --> 00:00:31,500
So we use the same page over and over again
10
00:00:31,500 --> 00:00:34,920
for different news items for different content.
11
00:00:34,920 --> 00:00:38,440
We would probably fetch the concrete content
12
00:00:38,440 --> 00:00:41,520
from some database when a user visits this detail page
13
00:00:41,520 --> 00:00:43,690
and then display it on the screen.
14
00:00:43,690 --> 00:00:46,220
So, it's the same component technically
15
00:00:46,220 --> 00:00:48,340
but with different content.
16
00:00:48,340 --> 00:00:50,620
And that's of course a totally realistic,
17
00:00:50,620 --> 00:00:53,580
I would even say very common scenario.
18
00:00:53,580 --> 00:00:56,660
So hard coding, the identifier,
19
00:00:56,660 --> 00:00:58,270
like something dash important
20
00:00:58,270 --> 00:01:01,860
like this in the file name is not very realistic.
21
00:01:01,860 --> 00:01:05,230
Instead, we wanna create a so-called dynamic page
22
00:01:05,230 --> 00:01:08,160
where the path segment to concrete value
23
00:01:08,160 --> 00:01:10,470
in the path can be dynamic,
24
00:01:10,470 --> 00:01:12,680
so that it's not just slash news,
25
00:01:12,680 --> 00:01:14,500
slash something important,
26
00:01:14,500 --> 00:01:16,570
but also slash something else
27
00:01:16,570 --> 00:01:21,570
or slash this course is great, whatever.
28
00:01:22,430 --> 00:01:25,820
So then this would be the identifier of a news item
29
00:01:25,820 --> 00:01:27,980
and we have a lot of different identifiers
30
00:01:27,980 --> 00:01:30,700
and we add new use all the time,
31
00:01:30,700 --> 00:01:32,280
but we always load the same page
32
00:01:32,280 --> 00:01:35,110
no matter what the concrete value here is.
33
00:01:35,110 --> 00:01:36,630
But then inside of the page,
34
00:01:36,630 --> 00:01:39,180
we simply have access to that value
35
00:01:39,180 --> 00:01:42,603
in the path so that we can fetch the proper data.
36
00:01:43,520 --> 00:01:47,910
And that is something we can implement with dynamic paths.
37
00:01:47,910 --> 00:01:50,737
For that, we change the file name here
38
00:01:50,737 --> 00:01:53,740
to a different file name, and we use a special syntax
39
00:01:53,740 --> 00:01:56,800
which will be understood by nextJS.
40
00:01:56,800 --> 00:01:58,680
We use square brackets here
41
00:01:58,680 --> 00:02:01,053
in the file name in front of the extension.
42
00:02:02,060 --> 00:02:05,040
If you have square brackets in your file name like this,
43
00:02:05,040 --> 00:02:09,370
this tells nextJS that this will be a dynamic page
44
00:02:09,370 --> 00:02:10,850
so that it should be loaded
45
00:02:10,850 --> 00:02:14,890
for different values in your path.
46
00:02:14,890 --> 00:02:17,560
And then you can add an identifier
47
00:02:17,560 --> 00:02:19,160
between those square brackets
48
00:02:19,160 --> 00:02:21,850
where the identifier name is totally up to you.
49
00:02:21,850 --> 00:02:25,240
Something like newsId, for example, like this.
50
00:02:25,240 --> 00:02:27,200
But this again is up to you,
51
00:02:27,200 --> 00:02:29,430
but you need those square brackets.
52
00:02:29,430 --> 00:02:31,810
This then tells nextJS that this page
53
00:02:31,810 --> 00:02:34,100
will be loaded for different values.
54
00:02:34,100 --> 00:02:37,860
So for example, for something important after slash news
55
00:02:37,860 --> 00:02:40,840
but also for any other identifier.
56
00:02:40,840 --> 00:02:42,300
And then in a next step,
57
00:02:42,300 --> 00:02:44,630
I will show you how you can get access
58
00:02:44,630 --> 00:02:48,130
to the concrete value entered here and how you can use that.
59
00:02:48,130 --> 00:02:50,250
But let's get there step by step.
60
00:02:50,250 --> 00:02:53,650
If we now saved as again, if I load this page
61
00:02:53,650 --> 00:02:56,530
for /news/thiscourseisgreat,
62
00:02:56,530 --> 00:02:58,280
I see the detail page,
63
00:02:58,280 --> 00:03:01,030
but I also see for something else
64
00:03:02,250 --> 00:03:05,620
or anything else we enter after slash news.
65
00:03:05,620 --> 00:03:09,120
So that is how we can add such a dynamic path here.
66
00:03:09,120 --> 00:03:13,070
And that is another key feature of nextJS.
67
00:03:13,070 --> 00:03:16,170
It's a feature that allows us to build truly dynamic
68
00:03:16,170 --> 00:03:19,902
and flexible websites with nextJS.
69
00:03:19,902 --> 00:03:24,902
But how can we now extract the entered path value
70
00:03:25,080 --> 00:03:27,680
inside of the component so that we can,
71
00:03:27,680 --> 00:03:30,750
for example, then fetch the correct news item
72
00:03:30,750 --> 00:03:31,640
from a database,
73
00:03:31,640 --> 00:03:34,453
let's say when a user visits this page?
5723
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.