Skip to the content.

What we will learn

The source of this summary The First link

The source of this summary The Second link


Dynamic Routes

It is the case where each page path depends on external data. Next.js allows you to statically generate pages with paths that depend on external data. This enables dynamic URLs in Next.js.

How to Statically Generate Pages with Dynamic Routes:

Implement getStaticPaths

we should set up the files:

  1. Create a file called [id].js inside the pages/posts directory.
  2. Remove first-post.js inside the pages/posts directory — we’ll no longer use this.
  3. Open pages/posts/[id].js in your editor and paste the following code.

         import Layout from '../../components/layout'
    
       export default function Post() {
         return <Layout>...</Layout>
       }
    

## Deploying Your Next.js App

### Push to GitHub

Before deploy, push our Next.js app to GitHub. This will make deployment easier.

To push to GitHub, you can run the following commands (replace with your GitHub username)

Deploy to Vercel

The easiest way to deploy Next.js to production is to use the Vercel platform developed by the creators of Next.js.

Vercel is a serverless platform for static and hybrid applications built to integrate with your headless content, commerce, or database.make it easy for frontend teams to develop, preview, and ship delightful user experiences, where performance is the default.

Create a Vercel Account

Vercel automatically detects that you have a Next.js app and chooses optimal build settings for you.

  1. Project Name
  2. Root Directory
  3. Build Command
  4. Output Directory
  5. Development Command

Vercel is made by the creators of Next.js and has first-class support for Next.js.When you deploy your Next.js app to Vercel, the following happens by default:

Vercel has many more features, such as:

  1. Custom Domains:

Once deployed on Vercel, assign a custom domain to your Next.js app.

  1. Environment Variables:

can also set environment variables on Vercel. You can then use those environment variables in Next.js app.

  1. Automatic HTTPS:

HTTPS is enabled by default (including custom domains) and doesn’t require extra configuration.