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,680
So now we all to learn about
2
00:00:03,680 --> 00:00:06,600
those nested folders to construct
3
00:00:06,600 --> 00:00:09,120
nested more complex puffs,
4
00:00:09,120 --> 00:00:13,110
or as an alternative to having a file off the same name,
5
00:00:13,110 --> 00:00:15,180
but maybe you all remember
6
00:00:15,180 --> 00:00:20,060
that last use case down there with the square brackets.
7
00:00:20,060 --> 00:00:24,020
This can be used to have a dynamic path
8
00:00:24,020 --> 00:00:26,850
with a dynamic path segment.
9
00:00:26,850 --> 00:00:31,670
And that's another key feature Next.js offers to us.
10
00:00:31,670 --> 00:00:34,990
Let's say here in this very simple dummy application
11
00:00:34,990 --> 00:00:38,560
we are working on in our portfolio folder,
12
00:00:38,560 --> 00:00:40,950
we don't just want to have the route path
13
00:00:40,950 --> 00:00:44,210
forward slash portfolio and the list path,
14
00:00:44,210 --> 00:00:46,830
but we also have different portfolio items
15
00:00:46,830 --> 00:00:49,630
different portfolio projects let's say,
16
00:00:49,630 --> 00:00:53,820
and those projects might have different ideas or slugs,
17
00:00:53,820 --> 00:00:57,710
and we want to load the different data in the same kind
18
00:00:57,710 --> 00:01:02,220
of component for those different slugs or IDs.
19
00:01:02,220 --> 00:01:04,390
That's exactly where we would create
20
00:01:04,390 --> 00:01:07,190
such a dynamic route component.
21
00:01:07,190 --> 00:01:11,330
And here the naming pattern is always exactly the same,
22
00:01:11,330 --> 00:01:13,760
you use square brackets,
23
00:01:13,760 --> 00:01:15,850
and then of course still .js
24
00:01:15,850 --> 00:01:18,500
because it's still a JavaScript file.
25
00:01:18,500 --> 00:01:20,720
And inside of the square brackets,
26
00:01:20,720 --> 00:01:23,170
any identifier of your choice.
27
00:01:23,170 --> 00:01:24,610
So this is up to you,
28
00:01:24,610 --> 00:01:26,830
it doesn't have to be ID,
29
00:01:26,830 --> 00:01:29,620
it just very often will be some kind of ID,
30
00:01:29,620 --> 00:01:31,030
but that's up to you,
31
00:01:31,030 --> 00:01:33,550
it could, for example, be project ID.,
32
00:01:33,550 --> 00:01:35,880
just to really emphasize that this
33
00:01:35,880 --> 00:01:38,290
can be any term you want.
34
00:01:38,290 --> 00:01:40,230
The square brackets matter though,
35
00:01:40,230 --> 00:01:43,170
because those tell Next.js
36
00:01:43,170 --> 00:01:45,770
that here we don't wanna have
37
00:01:45,770 --> 00:01:48,670
slash portfolio, slash project ID,
38
00:01:48,670 --> 00:01:51,310
but that instead this is a placeholder
39
00:01:51,310 --> 00:01:55,810
for any kind of value which we then will have access
40
00:01:55,810 --> 00:01:59,370
to in the component to load different kinds of data,
41
00:01:59,370 --> 00:02:02,200
but that will be the next step.
42
00:02:02,200 --> 00:02:03,980
So therefore let's know save this,
43
00:02:03,980 --> 00:02:06,380
and even though this might look strange,
44
00:02:06,380 --> 00:02:09,530
this is a perfectly valid file name.
45
00:02:09,530 --> 00:02:12,500
And now in here we can create a new function,
46
00:02:12,500 --> 00:02:16,990
the portfolio project page function maybe,
47
00:02:16,990 --> 00:02:20,500
where we returned and number div where we say
48
00:02:20,500 --> 00:02:24,250
the portfolio project page.
49
00:02:24,250 --> 00:02:26,710
And then just as before we simply
50
00:02:26,710 --> 00:02:30,373
export this page component.
51
00:02:31,330 --> 00:02:35,450
Now how can we load this component or this page?
52
00:02:35,450 --> 00:02:37,920
Well, it's a place holder as I said,
53
00:02:37,920 --> 00:02:40,650
and it's in the portfolio folder,
54
00:02:40,650 --> 00:02:41,880
hence what we can do,
55
00:02:41,880 --> 00:02:45,150
is we can enter portfolio slash,
56
00:02:45,150 --> 00:02:47,440
and then any value of your choice,
57
00:02:47,440 --> 00:02:49,340
for example something
58
00:02:49,340 --> 00:02:51,530
and you see the portfolio project page.
59
00:02:51,530 --> 00:02:55,290
Also if we use slash one instead of slash something,
60
00:02:55,290 --> 00:02:57,660
or slash hello,
61
00:02:57,660 --> 00:02:59,870
so whatever value we enter here,
62
00:02:59,870 --> 00:03:03,180
this is valid because here we defined
63
00:03:03,180 --> 00:03:05,730
that we wanna accept any value that
64
00:03:05,730 --> 00:03:09,390
we just have a placeholder here and now we're filling
65
00:03:09,390 --> 00:03:13,290
in that concrete value for that placeholder.
66
00:03:13,290 --> 00:03:16,460
Please also notice though, that slash list
67
00:03:16,460 --> 00:03:18,880
still loads the list page,
68
00:03:18,880 --> 00:03:23,880
since Next.js is smart and checks your other files as well.
69
00:03:24,770 --> 00:03:28,090
So if it sees that a value could be treated as a value
70
00:03:28,090 --> 00:03:29,510
for this placeholder,
71
00:03:29,510 --> 00:03:32,010
it all checks if you maybe have a more
72
00:03:32,010 --> 00:03:35,580
concrete file for that exact value.
73
00:03:35,580 --> 00:03:39,170
So for a slash list after slash portfolio,
74
00:03:39,170 --> 00:03:43,220
it sees that there is a list file in the portfolio folder
75
00:03:43,220 --> 00:03:47,810
and it prioritize a that file over this dynamic file.
76
00:03:47,810 --> 00:03:49,460
And that's a great behavior,
77
00:03:49,460 --> 00:03:51,550
because it means that you can have
78
00:03:51,550 --> 00:03:54,480
static predefined route page files,
79
00:03:54,480 --> 00:03:57,720
next to dynamic ones like this one.
80
00:03:57,720 --> 00:04:00,770
But what can we now do with that file?
81
00:04:00,770 --> 00:04:02,730
It's a placeholder,
82
00:04:02,730 --> 00:04:05,400
but what's the real benefit we get
83
00:04:05,400 --> 00:04:07,633
by using such a placeholder.
84
00:04:08,880 --> 00:04:10,720
As I said a common scenario
85
00:04:10,720 --> 00:04:13,710
for using such a dynamic page would be,
86
00:04:13,710 --> 00:04:15,610
that you have the same kind of page
87
00:04:15,610 --> 00:04:18,399
that should be loaded for different pieces of data,
88
00:04:18,399 --> 00:04:20,110
different products in our shop
89
00:04:20,110 --> 00:04:22,460
or different blog posts in a blog,
90
00:04:22,460 --> 00:04:25,390
or like in this case, different projects
91
00:04:25,390 --> 00:04:28,513
we wanna show on our portfolio page, for example.
92
00:04:29,390 --> 00:04:33,020
So therefore now inside of this page component,
93
00:04:33,020 --> 00:04:36,170
we typically now wanna use the concrete value
94
00:04:36,170 --> 00:04:37,580
that was entered,
95
00:04:37,580 --> 00:04:40,080
so the concrete project ID here,
96
00:04:40,080 --> 00:04:43,500
and then probably reach out to some database
97
00:04:43,500 --> 00:04:44,900
or something like this,
98
00:04:44,900 --> 00:04:46,510
fetch data from there,
99
00:04:46,510 --> 00:04:48,810
and then use that concrete data
100
00:04:48,810 --> 00:04:52,403
in this component to bring that data to the screen.
7583
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.