Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,140 --> 00:00:03,540
So let's now implement
2
00:00:03,540 --> 00:00:07,210
those pages, those routes together.
3
00:00:07,210 --> 00:00:10,870
And for this, of course, we go to this pages folder
4
00:00:10,870 --> 00:00:13,840
and in there we can add a new file.
5
00:00:13,840 --> 00:00:17,580
A new file for our route page, for our home page,
6
00:00:17,580 --> 00:00:21,500
so to say, the index.js file.
7
00:00:21,500 --> 00:00:23,600
This will then, hold the component
8
00:00:23,600 --> 00:00:27,210
that should be loaded, if we visit local host,
9
00:00:27,210 --> 00:00:30,980
or whatever our domain is /nothing.
10
00:00:30,980 --> 00:00:34,440
And therefore, in here, I'll add the HomePage function.
11
00:00:34,440 --> 00:00:38,430
So, a functional component, which I simply name HomePage.
12
00:00:38,430 --> 00:00:42,760
And, of course, we also wanna export this as a default.
13
00:00:42,760 --> 00:00:47,460
We need to do that for Next.js to find that component.
14
00:00:47,460 --> 00:00:50,120
And then, in there, we return the JSX code
15
00:00:50,120 --> 00:00:51,790
that belongs to this component.
16
00:00:51,790 --> 00:00:55,150
And, for the moment, I'll just return a div here
17
00:00:55,150 --> 00:00:58,730
with a h1 tag, where I say The Home Page.
18
00:00:58,730 --> 00:01:00,720
But in this course section,
19
00:01:00,720 --> 00:01:02,820
unlike in the last course section,
20
00:01:02,820 --> 00:01:07,100
we are also going to add more output
21
00:01:07,100 --> 00:01:09,680
and more logic to our application.
22
00:01:09,680 --> 00:01:12,730
So, we'll not stick to such dummy output.
23
00:01:12,730 --> 00:01:13,980
But, for the moment, we will,
24
00:01:13,980 --> 00:01:16,677
and we will continue adding the other routes.
25
00:01:16,677 --> 00:01:19,890
Now, we also need a route for all events
26
00:01:19,890 --> 00:01:22,960
and then, for that slug.
27
00:01:22,960 --> 00:01:26,680
So, for consuming all dynamic segments
28
00:01:26,680 --> 00:01:30,323
and for a single dynamic segment for a single event.
29
00:01:31,160 --> 00:01:36,160
Hence, we can add an events.js file for our events page,
30
00:01:37,230 --> 00:01:41,360
which lists all events or, alternatively,
31
00:01:41,360 --> 00:01:43,390
instead of adding that file
32
00:01:43,390 --> 00:01:47,260
we add an events folder in the pages folder.
33
00:01:47,260 --> 00:01:52,260
And, in that folder, we then add an index.js file
34
00:01:52,490 --> 00:01:57,420
and that's the exact equivalent to adding an events.js file.
35
00:01:57,420 --> 00:02:00,220
And I will go for this approach also
36
00:02:00,220 --> 00:02:02,870
because we'll need that folder later
37
00:02:02,870 --> 00:02:07,520
to set up nested routes for a single event, for example,
38
00:02:07,520 --> 00:02:10,850
because, keep in mind that, for a single event
39
00:02:10,850 --> 00:02:13,410
for that event detail page I want
40
00:02:13,410 --> 00:02:17,080
to have /events/some dynamic segment.
41
00:02:17,080 --> 00:02:21,080
So, for that nested route, like for all nested routes,
42
00:02:21,080 --> 00:02:26,080
we will need this sub folder, this events sub folder.
43
00:02:26,160 --> 00:02:29,650
Otherwise, you won't be able to set up such a route.
44
00:02:29,650 --> 00:02:32,363
Hence, we'll need that events folder anyways,
45
00:02:33,470 --> 00:02:35,430
and, therefore, we can already create it
46
00:02:35,430 --> 00:02:38,600
for the All Events page as well.
47
00:02:38,600 --> 00:02:41,520
So, in there, we add another functional component
48
00:02:41,520 --> 00:02:43,840
and I'll name it AllEventsPage.
49
00:02:43,840 --> 00:02:46,260
Of course, those names are up to you though.
50
00:02:46,260 --> 00:02:49,950
You can name your page components however you want.
51
00:02:49,950 --> 00:02:52,800
But I'll go with this name and then return.
52
00:02:52,800 --> 00:02:56,363
Another div here where I say All Events.
53
00:02:57,250 --> 00:02:59,380
Again, that's just some dummy content.
54
00:02:59,380 --> 00:03:04,380
We'll replace that with actual output and some logic later.
55
00:03:04,560 --> 00:03:07,680
Now, two more routes, two more pages to go.
56
00:03:07,680 --> 00:03:11,810
And the first one will be the page for a single event.
57
00:03:11,810 --> 00:03:14,580
So, when we selected an event for displaying
58
00:03:14,580 --> 00:03:17,740
all the detail information for this event.
59
00:03:17,740 --> 00:03:21,380
Now, we wanna select that event dynamically by ID.
60
00:03:21,380 --> 00:03:23,470
And, therefore, the page should have
61
00:03:23,470 --> 00:03:28,470
a dynamic segment in its URL, so in it's path.
62
00:03:28,860 --> 00:03:30,530
And you'll learn how that works.
63
00:03:30,530 --> 00:03:35,160
We set up a file with square brackets in the file name
64
00:03:35,160 --> 00:03:37,380
and then between the square brackets,
65
00:03:37,380 --> 00:03:40,130
any identifier of our choice.
66
00:03:40,130 --> 00:03:45,130
For example, Id, or simply eventId, whatever you want.
67
00:03:47,220 --> 00:03:51,550
And I'll go for eventId written like this with a capital I
68
00:03:51,550 --> 00:03:56,020
so that I can then later extract that actual event ID
69
00:03:56,020 --> 00:03:58,420
from the router, from the query property,
70
00:03:58,420 --> 00:04:02,203
as you learned it, by that key, so by using that key.
71
00:04:03,210 --> 00:04:06,950
And, hence, in this square bracket eventId file
72
00:04:06,950 --> 00:04:10,917
we add the EventDetailPage and we, of course,
73
00:04:13,670 --> 00:04:17,370
also export that page, the EventDetail page,
74
00:04:17,370 --> 00:04:18,950
and then here, for the moment,
75
00:04:18,950 --> 00:04:22,837
I'll also adjust return a div, where I say Event Detail.
76
00:04:25,180 --> 00:04:28,760
Now, the last page, the last route I wanna add,
77
00:04:28,760 --> 00:04:32,420
therefore is this slug route, so which consumes
78
00:04:32,420 --> 00:04:36,020
all segments, even if that would be multiple segments
79
00:04:36,020 --> 00:04:38,870
after, in this case, events
80
00:04:38,870 --> 00:04:42,770
because I'll create it in the events sub folder.
81
00:04:42,770 --> 00:04:47,770
And, for this, the syntax also is to use square brackets,
82
00:04:47,800 --> 00:04:50,410
but then we also add three dots,
83
00:04:50,410 --> 00:04:52,870
like the spread operator in JavaScript,
84
00:04:52,870 --> 00:04:56,400
or the rest parameters, syntax from JavaScript,
85
00:04:56,400 --> 00:05:01,040
and then any identifier of our choice, for example, slug.
86
00:05:01,040 --> 00:05:03,120
But, again, that's just something
87
00:05:03,120 --> 00:05:05,300
you will see quite a lot, slug.
88
00:05:05,300 --> 00:05:08,650
But you can, of course, use any identifier you want.
89
00:05:08,650 --> 00:05:11,520
Now, you might think that this maybe clashes
90
00:05:11,520 --> 00:05:15,170
with the event ID, but as long as we enter more
91
00:05:15,170 --> 00:05:19,580
than one dynamic parameter after /events, it won't.
92
00:05:19,580 --> 00:05:22,410
And that's exactly how we're going to use that.
93
00:05:22,410 --> 00:05:25,810
If we just have /events/something,
94
00:05:25,810 --> 00:05:29,160
so just one segment after /events,
95
00:05:29,160 --> 00:05:31,340
then the slug will not kick in.
96
00:05:31,340 --> 00:05:33,680
Instead, this eventId route will
97
00:05:33,680 --> 00:05:38,503
then handle such a request, or such a URL in the end,
98
00:05:40,650 --> 00:05:43,790
as you will see throughout this section.
99
00:05:43,790 --> 00:05:46,100
So, therefore, here in this slug file
100
00:05:46,100 --> 00:05:48,303
I'll name this FilteredEventsPage
101
00:05:49,880 --> 00:05:54,180
because here I wanna show a list of filtered events.
102
00:05:54,180 --> 00:05:58,640
And then, we can export this here as well.
103
00:05:58,640 --> 00:06:01,560
And, of course, in the component all the returns
104
00:06:01,560 --> 00:06:06,560
some dummy content here, Filtered Events, like this.
105
00:06:07,120 --> 00:06:09,460
And I did spend a lot of time explaining this,
106
00:06:09,460 --> 00:06:13,310
but these are, of course, some key features of Next.js,
107
00:06:13,310 --> 00:06:15,280
so I want to make sure that we're all
108
00:06:15,280 --> 00:06:17,850
on the same page regarding them.
109
00:06:17,850 --> 00:06:20,520
Now, with all of that, we can start
110
00:06:20,520 --> 00:06:23,380
the development server with npm run dev,
111
00:06:23,380 --> 00:06:24,950
and this will now start it up.
112
00:06:24,950 --> 00:06:27,390
And we can now open the browser
113
00:06:27,390 --> 00:06:32,390
and visit local host 3000, and we see the Home Page.
114
00:06:32,590 --> 00:06:36,170
Now, if you visit local host 3000/events
115
00:06:36,170 --> 00:06:38,420
we see the All Events page,
116
00:06:38,420 --> 00:06:43,420
if I enter /events/ let's say e1, as a dummy event ID,
117
00:06:44,410 --> 00:06:47,040
I see the Event Detail page.
118
00:06:47,040 --> 00:06:49,893
And if we try out this slug concept,
119
00:06:51,110 --> 00:06:55,650
and we try to filter for events that take place in 2021
120
00:06:55,650 --> 00:07:00,650
and then May by adding the segments /2021/05
121
00:07:02,260 --> 00:07:06,280
after events, I see the Filtered Events page.
122
00:07:06,280 --> 00:07:10,060
Of course, it will be our job throughout this section
123
00:07:10,060 --> 00:07:13,070
to make sure that on that Filtered Events page
124
00:07:13,070 --> 00:07:16,880
we then extract the actual segment values
125
00:07:16,880 --> 00:07:21,060
from the URL and then find appropriate events.
126
00:07:21,060 --> 00:07:23,790
But that's exactly part of what we build
127
00:07:23,790 --> 00:07:26,090
throughout this section.
128
00:07:26,090 --> 00:07:28,200
And therefore, with that, we now got
129
00:07:28,200 --> 00:07:29,860
the basic setup we need.
130
00:07:29,860 --> 00:07:33,893
Now, we can gradually start filling that with life.
10606
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.