Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,170 --> 00:00:04,560
So now we know about this concept
2
00:00:04,560 --> 00:00:07,760
of using files in the pages folder
3
00:00:07,760 --> 00:00:08,930
for creating routes,
4
00:00:08,930 --> 00:00:11,250
which then load these different components
5
00:00:11,250 --> 00:00:13,010
that live in these files
6
00:00:13,010 --> 00:00:17,500
and we also see that this server-side pre-rendering works
7
00:00:17,500 --> 00:00:19,090
out of the box.
8
00:00:19,090 --> 00:00:20,400
Now, let's dig a bit deeper
9
00:00:20,400 --> 00:00:23,620
into that file-based routing system though.
10
00:00:23,620 --> 00:00:27,140
For example, there is an important alternative
11
00:00:27,140 --> 00:00:28,600
you should be aware of
12
00:00:28,600 --> 00:00:32,000
when it comes to organizing your files and folders.
13
00:00:32,000 --> 00:00:33,620
We've got this index.js file
14
00:00:33,620 --> 00:00:37,530
and that loads the root page or slash nothing
15
00:00:37,530 --> 00:00:42,300
because it's the index.js file directly in the pages folder.
16
00:00:42,300 --> 00:00:44,670
Now, for the news page, /news,
17
00:00:44,670 --> 00:00:46,620
we've got the news.js file.
18
00:00:46,620 --> 00:00:49,060
We always have an alternative
19
00:00:49,060 --> 00:00:51,790
to using such a named file name.
20
00:00:51,790 --> 00:00:55,310
So a file named differently than index.js.
21
00:00:55,310 --> 00:00:58,350
We could also create a news sub-folder
22
00:00:58,350 --> 00:01:01,890
in the pages folder, move news.js in there
23
00:01:01,890 --> 00:01:04,870
and then rename it to index.js
24
00:01:04,870 --> 00:01:07,920
using that special index.js file name again.
25
00:01:07,920 --> 00:01:10,370
Now, this page would still be loaded
26
00:01:10,370 --> 00:01:13,670
by visiting our-domain.com/news
27
00:01:13,670 --> 00:01:15,710
because we're in the news folder.
28
00:01:15,710 --> 00:01:17,130
And that's important.
29
00:01:17,130 --> 00:01:21,360
Folders, which you create in your pages folder also act
30
00:01:21,360 --> 00:01:23,420
as path segments.
31
00:01:23,420 --> 00:01:24,660
And it's totally up to you
32
00:01:24,660 --> 00:01:27,810
whether you wanna go with news.js
33
00:01:27,810 --> 00:01:32,700
in the root pages folder or index.js in the news folder.
34
00:01:32,700 --> 00:01:34,280
Now, it does matter though
35
00:01:34,280 --> 00:01:37,190
as soon as you start creating nested paths,
36
00:01:37,190 --> 00:01:38,578
and that's what I wanna do now.
37
00:01:38,578 --> 00:01:40,530
If we wanna have a path
38
00:01:40,530 --> 00:01:45,530
that is something like news.something-important
39
00:01:46,500 --> 00:01:49,920
where something-important is the identifier
40
00:01:49,920 --> 00:01:52,610
of the specific news item you wanna load,
41
00:01:52,610 --> 00:01:56,330
then you need to create a file in such a sub-folder
42
00:01:56,330 --> 00:01:59,850
because otherwise, you can't create such a nested path.
43
00:01:59,850 --> 00:02:02,490
After all, we have two segments here
44
00:02:02,490 --> 00:02:05,820
and if we just create files directly in the pages folder,
45
00:02:05,820 --> 00:02:09,820
we're limited to one segment, the file name.
46
00:02:09,820 --> 00:02:13,150
So therefore, if we want to have such a nested path,
47
00:02:13,150 --> 00:02:14,500
so more than one segment,
48
00:02:14,500 --> 00:02:16,650
we need to create a sub-folder
49
00:02:16,650 --> 00:02:18,830
and then we can also create the root page
50
00:02:18,830 --> 00:02:21,530
for that path with index.js
51
00:02:21,530 --> 00:02:26,530
and then create the something-important.js file
52
00:02:26,660 --> 00:02:30,060
as a sibling file to index.js.
53
00:02:30,060 --> 00:02:33,220
So now we have two different pages
54
00:02:33,220 --> 00:02:36,120
that start with /news,
55
00:02:36,120 --> 00:02:39,760
/news/ nothing loads the component in the index.js file,
56
00:02:39,760 --> 00:02:43,030
/news/something-important
57
00:02:43,030 --> 00:02:46,020
will load the component we create in here.
58
00:02:46,020 --> 00:02:49,100
Now, of course, here again we could alternatively also
59
00:02:49,100 --> 00:02:51,370
create another nested sub-folder,
60
00:02:51,370 --> 00:02:54,340
something-important with the index.js file in there.
61
00:02:54,340 --> 00:02:56,600
That would again be the alternative
62
00:02:56,600 --> 00:03:00,230
to using such a named file name in the news folder.
63
00:03:00,230 --> 00:03:02,404
But I hope you get the idea by now.
64
00:03:02,404 --> 00:03:05,380
Now, with that, I could copy this code
65
00:03:05,380 --> 00:03:07,400
from index.js in the news folder
66
00:03:07,400 --> 00:03:11,370
and bring it into the something-important page here
67
00:03:11,370 --> 00:03:14,980
and then name this DetailPage maybe
68
00:03:14,980 --> 00:03:17,590
because that should be the page holding the details
69
00:03:17,590 --> 00:03:19,550
for a specific news item
70
00:03:19,550 --> 00:03:21,020
and this page would now be loaded
71
00:03:21,020 --> 00:03:24,453
for /news/something-important.
72
00:03:25,350 --> 00:03:27,140
And hence, if we save everything
73
00:03:27,140 --> 00:03:31,270
and we visit /news, we see The News page,
74
00:03:31,270 --> 00:03:35,100
and if I visit /news/something-important,
75
00:03:35,100 --> 00:03:38,180
then we see The Detail Page.
76
00:03:38,180 --> 00:03:40,910
So that's how this works.
77
00:03:40,910 --> 00:03:43,640
But there is still another important concept
78
00:03:43,640 --> 00:03:45,523
which we have't touched on yet.
5926
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.