All language subtitles for 025 Preparing Paths with _getStaticPaths_ & Working With Fallback Pages_en

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian Download
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:02,427 --> 00:00:03,719 getStaticPaths 2 00:00:03,719 --> 00:00:05,331 is another function 3 00:00:05,331 --> 00:00:06,914 NextJS understands, 4 00:00:08,490 --> 00:00:10,275 just like getStaticProps 5 00:00:10,275 --> 00:00:12,357 and getServerSideProps. 6 00:00:12,357 --> 00:00:16,172 And getStaticPaths is a function you need to export 7 00:00:16,172 --> 00:00:18,880 in a page component file. 8 00:00:18,880 --> 00:00:21,511 If it's a dynamic page 9 00:00:21,511 --> 00:00:26,013 like we have it here and you're using getStaticProps, 10 00:00:26,013 --> 00:00:28,972 not if you're using getServerSideProps 11 00:00:28,972 --> 00:00:32,077 and not if you're using neever get static 12 00:00:32,077 --> 00:00:33,700 nor getServerSideProps 13 00:00:33,700 --> 00:00:38,000 but it is needed if you do use getStaticProps. 14 00:00:38,000 --> 00:00:42,230 So in that case, you need to export another function here 15 00:00:42,230 --> 00:00:44,560 in this page component file. 16 00:00:44,560 --> 00:00:48,300 And that's the getStaticPaths function. 17 00:00:48,300 --> 00:00:50,900 And this can also be a async function 18 00:00:50,900 --> 00:00:54,610 so that you can use a single weight in there. 19 00:00:54,610 --> 00:00:58,420 Now what's the deal with getStaticPaths though. 20 00:00:58,420 --> 00:01:01,930 To understand it, let's again think about the fact 21 00:01:01,930 --> 00:01:04,110 that with getStaticProps 22 00:01:04,110 --> 00:01:08,490 a page is pre-generated during the build process. 23 00:01:08,490 --> 00:01:10,280 Now, what does this mean? 24 00:01:10,280 --> 00:01:15,280 This means that of course, NextJS needs to pre-generate 25 00:01:15,620 --> 00:01:20,030 all versions of this dynamic page in advance 26 00:01:20,030 --> 00:01:22,900 for all the supported IDs. 27 00:01:22,900 --> 00:01:26,890 Because since this is dynamic, NextJS needs to know 28 00:01:26,890 --> 00:01:31,220 for which ID values it should pre-generate the page. 29 00:01:31,220 --> 00:01:35,130 Because how would it pre-generate this page otherwise? 30 00:01:35,130 --> 00:01:38,750 We get the ID from the URL here. 31 00:01:38,750 --> 00:01:42,230 Great, but keep in mind that this is not pre-generated 32 00:01:42,230 --> 00:01:45,430 when a user visits this page with a specific value 33 00:01:45,430 --> 00:01:49,120 in the URL, but during the build process. 34 00:01:49,120 --> 00:01:53,660 So here we need to pre-generated for all the URLs, 35 00:01:53,660 --> 00:01:57,890 for all the meetup ID values users might be entering 36 00:01:57,890 --> 00:01:59,710 at runtime. 37 00:01:59,710 --> 00:02:03,030 And if they enter an ID for which we didn't pre-generate 38 00:02:03,030 --> 00:02:06,570 the page, they will see a 404 error. 39 00:02:06,570 --> 00:02:08,740 But because that is how it works, 40 00:02:08,740 --> 00:02:11,260 we need to add getStaticPaths 41 00:02:11,260 --> 00:02:13,889 which has the job of returning an object 42 00:02:13,889 --> 00:02:18,820 where we describe all the dynamic segment values. 43 00:02:18,820 --> 00:02:21,140 So all the meetup IDs in this case, 44 00:02:21,140 --> 00:02:24,533 for which this page should be pre-generated. 45 00:02:25,510 --> 00:02:28,700 Now for this, this object needs to have a paths key, 46 00:02:28,700 --> 00:02:30,200 which is an array. 47 00:02:30,200 --> 00:02:33,020 And in that array, you must have multiple objects 48 00:02:33,020 --> 00:02:37,350 one object per version of this dynamic page. 49 00:02:37,350 --> 00:02:39,700 Where this object has a parans key. 50 00:02:39,700 --> 00:02:43,800 That's a must have, which then itself again is an object 51 00:02:43,800 --> 00:02:45,540 with all the key value pairs 52 00:02:45,540 --> 00:02:47,810 that might lead to your dynamic page. 53 00:02:47,810 --> 00:02:50,750 So if you have multiple dynamic segments, 54 00:02:50,750 --> 00:02:54,880 then you would have multiple keys in this nested object. 55 00:02:54,880 --> 00:02:59,320 Here we only have meetup ID as a single dynamic segment. 56 00:02:59,320 --> 00:03:01,460 And hence here in this parans object, 57 00:03:01,460 --> 00:03:03,490 we would add a meetup ID key 58 00:03:03,490 --> 00:03:07,330 and then enter the concrete value for meetup ID 59 00:03:07,330 --> 00:03:10,480 for which this page should be pre-generated. 60 00:03:10,480 --> 00:03:13,030 And if we have multiple possible values. 61 00:03:13,030 --> 00:03:16,070 Like in this case where I have, M1 and M2 62 00:03:16,070 --> 00:03:21,070 we would return a paths array with two objects inside of it, 63 00:03:21,070 --> 00:03:24,723 where the other one uses M2 as a meetup ID. 64 00:03:26,070 --> 00:03:29,470 Now, in reality, you would of course not hard-code this 65 00:03:29,470 --> 00:03:30,670 as a developer, 66 00:03:30,670 --> 00:03:34,370 but you would also fetch your supported IDs from a database 67 00:03:34,370 --> 00:03:38,910 or from an API and generate this array dynamically. 68 00:03:38,910 --> 00:03:41,500 And we are also going to do that later, 69 00:03:41,500 --> 00:03:43,803 but for the moment let's hard-code it. 70 00:03:45,030 --> 00:03:48,680 With that, if you save that file with getStaticPaths added 71 00:03:48,680 --> 00:03:52,010 with this code and with getStaticProps 72 00:03:52,010 --> 00:03:55,407 still being in there, with that if you now reload, 73 00:03:55,407 --> 00:03:57,690 we don't get this error anymore. 74 00:03:57,690 --> 00:04:01,720 Instead we get this error regarding the fallback key 75 00:04:01,720 --> 00:04:04,380 instead of getStaticPaths. 76 00:04:04,380 --> 00:04:06,530 And that's another piece of configuration, 77 00:04:06,530 --> 00:04:09,550 which you need to add in this returned object 78 00:04:09,550 --> 00:04:12,020 next to your paths key, 79 00:04:12,020 --> 00:04:14,420 the fallback key. 80 00:04:14,420 --> 00:04:18,920 This key tells NextJS whether your paths array 81 00:04:18,920 --> 00:04:22,430 contains all supported parameter values 82 00:04:22,430 --> 00:04:24,850 or just some of them. 83 00:04:24,850 --> 00:04:28,310 If you set fall back to false, 84 00:04:28,310 --> 00:04:29,810 you say that your paths 85 00:04:29,810 --> 00:04:33,800 contains all supported meetup ID values. 86 00:04:33,800 --> 00:04:36,340 That means that if the user enters anything 87 00:04:36,340 --> 00:04:38,890 that's not supported here, for example, M3 88 00:04:40,034 --> 00:04:43,470 he or she would see a 404 error. 89 00:04:43,470 --> 00:04:46,100 If you set fall back to true on the other hand, 90 00:04:46,100 --> 00:04:48,830 NextJS would try to generate a page 91 00:04:48,830 --> 00:04:52,047 for this meetup ID dynamically on the server 92 00:04:52,047 --> 00:04:53,473 for the incoming request. 93 00:04:54,350 --> 00:04:56,090 Fall back is a nice feature 94 00:04:56,090 --> 00:04:59,990 because it allows you to pre-generate some of your pages 95 00:04:59,990 --> 00:05:02,900 for specific meetup ID values. 96 00:05:02,900 --> 00:05:07,170 For example the pages which are visited most frequently 97 00:05:07,170 --> 00:05:10,360 and then pre-generate the missing ones dynamically 98 00:05:10,360 --> 00:05:13,023 when requests for them are coming in. 99 00:05:13,860 --> 00:05:16,520 Here however, I'll set fallback to false 100 00:05:16,520 --> 00:05:21,500 to indicate that I defined all supported paths here. 101 00:05:21,500 --> 00:05:24,140 Now, if you wanna learn more about fallback and so on, 102 00:05:24,140 --> 00:05:27,630 I do cover that in greater detail in my full course. 103 00:05:27,630 --> 00:05:28,980 But the general concept 104 00:05:28,980 --> 00:05:31,570 is that we can simply define some paths 105 00:05:31,570 --> 00:05:33,240 instead of all paths. 106 00:05:33,240 --> 00:05:35,750 If we, for example, have hundreds of pages 107 00:05:35,750 --> 00:05:38,480 and we don't wanna pre-generate all of them, 108 00:05:38,480 --> 00:05:41,143 but maybe just our most popular pages. 109 00:05:42,090 --> 00:05:44,580 And therefore with fallback added now, 110 00:05:44,580 --> 00:05:46,630 if we save this again and reload, 111 00:05:46,630 --> 00:05:51,010 now we successfully load the page for this first meetup. 112 00:05:51,010 --> 00:05:53,720 If I go to M2, that also works. 113 00:05:53,720 --> 00:05:57,610 But if I enter M3, I get the default 404 page here 114 00:05:57,610 --> 00:06:00,470 because I had fallback set to false 115 00:06:00,470 --> 00:06:04,483 and M3 is not one of the supported parameters here. 116 00:06:05,480 --> 00:06:07,614 That's how this works. 117 00:06:07,614 --> 00:06:08,487 And getStaticPaths 118 00:06:08,487 --> 00:06:11,160 therefore is another important function, 119 00:06:11,160 --> 00:06:15,050 which you need in dynamic pages to tell NextJS 120 00:06:15,050 --> 00:06:17,564 for which dynamic parameter values 121 00:06:17,564 --> 00:06:20,570 this page should be pre-generated. 122 00:06:20,570 --> 00:06:24,360 And then again, getStaticProps executes for every page. 123 00:06:24,360 --> 00:06:28,070 So for every meetup ID value allows you to fetch data 124 00:06:28,070 --> 00:06:30,930 for that meetup and allows you to return props 125 00:06:30,930 --> 00:06:32,540 for that meetup. 126 00:06:32,540 --> 00:06:35,960 And as a side note here, where I locked the meetup ID 127 00:06:35,960 --> 00:06:39,010 we do see that here in this terminal. 128 00:06:39,010 --> 00:06:41,680 We don't see it in the browser, 129 00:06:41,680 --> 00:06:42,910 developer tools, 130 00:06:42,910 --> 00:06:44,790 here the console is empty 131 00:06:44,790 --> 00:06:48,930 because I mentioned that this is called the code 132 00:06:48,930 --> 00:06:52,570 instead of getStaticProps, which runs during build time. 133 00:06:52,570 --> 00:06:54,770 And when running in the development server 134 00:06:54,770 --> 00:06:57,440 it does run for every incoming request 135 00:06:57,440 --> 00:07:00,700 but only on the developer server side. 136 00:07:00,700 --> 00:07:03,980 So we only see it in the terminal of this developer server 137 00:07:03,980 --> 00:07:07,080 then, and not in the browser. 138 00:07:07,080 --> 00:07:10,510 That's how it getStaticProps works for dynamic pages 139 00:07:10,510 --> 00:07:12,590 and that's how it getStaticPaths works 140 00:07:12,590 --> 00:07:14,233 and why it is required. 11005

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.