You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -346,7 +360,10 @@ Submit that form to create a new post, and you'll build that page next!
346
360
347
361
Statically generating pages during the build process improves performance. But, dynamically created posts still need to not `404`.
348
362
349
-
To solve this, create **pages/posts/[id].js** and paste in the following content:
363
+
To solve this, create a new folder within **/pages** named "posts". Next, create a new file within this new **/posts** named **[id].js** to create the structure:
364
+
**pages/posts/[id].js**.
365
+
366
+
Paste the following content into the newly made **[id].js** file:
@@ -441,9 +445,7 @@ Let's walk through some of this file:
441
445
442
446
-**Amplify.configure** – For authenticated requests to work on the server, your client has to be configured with `ssr: true` to make credentials available on subsequent requests.
443
447
444
-
-**getStaticPaths** – Because the value of `[id]` isn't known at build-time, you need to provide all possible `paths` for Next.js to render pages for. You do this by querying all posts with `API.graphql`, and mapping each `post` into `{ params: { id: post.id }}`. These `params` are passed to `getStaticProps` next. Note that you return `fallback: true`. If this value were `false`, then any _new_ posts would return a `404` because they didn't exist at build-time. With `true`, static pages are returned quickly, while any new `id`s are looked up once.
445
-
446
-
-**getStaticProps** – Because the `Post` components props aren't dynamic per-request, they're provided statically from `getStaticPaths` as `params`. Here, you use `params.id` to query for that specific post with `API.graphql`.
448
+
-**getServerSideProps** - This will only run on the server-side and allows for fetching of data as we make the request. Here, you use params.id to query for that specific post with API.graphql and await the response.
447
449
448
450
-**Post** – `Post` is a functional component that renders the provided prop `post`. Because `fallback: true` was specified above, you have to account for a "loading" state while a new post may be fetched.
This creates a new Next.js app in a directory called `next-amplified` and then switches us into that new directory.
10
+
You'll need to select if you'd like to build this project with TypeScript (Yes) or JavaScript (No), and then if you'd like ESLint to be configured as well. Note that if you select Typescript, there may be additional changes you'll need to make throughout this guide to files and configurations.
11
+
12
+
Once these have been selected, a new Next.js app will be created in a directory called `next-amplified` and then switches us into that new directory.
11
13
12
14
Now that you're in the root of the project, you can run the app by using the following command:
> Where possible the CLI will infer the proper configuration based on the type of project Amplify is being initialized in. In this case it knew you are using Create Next App and provided the proper configuration for type of app, framework, source, distribution, build, and start options.
0 commit comments