FG
🌐 Web & Full-StackVercelproduction

Next.js App Router dynamic [slug] routes return 404 on Vercel after deploy

Fresh4 months ago
Mar 14, 20260 views
Confidence Score71%
71%

Problem

Dynamic routes like /issue/[slug] and /user/[id] return 404 on Vercel in production even though they work fine locally. The routes exist in the file system and localhost serves them correctly. The issue is Next.js attempting to statically generate these pages at build time when the database isn't available, resulting in 404 fallbacks being deployed.

Error Output

404 | This page could not be found.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
68% confidence80% success rate3 verificationsLast verified Mar 14, 2026

Add export const dynamic = "force-dynamic" and verify DATABASE_URL in Vercel

Low Risk

Without force-dynamic, Next.js attempts to pre-render dynamic routes at build time. Without a database connection, the build silently fails for those routes and deploys 404 fallbacks.

68

Trust Score

3 verifications

80% success
  1. 1

    Add force-dynamic to dynamic route files

    Add to every page.tsx under dynamic segments like [slug] or [id]:

    typescript
    export const dynamic = 'force-dynamic'
  2. 2

    Set DATABASE_URL in Vercel dashboard

    Vercel Dashboard → your project → Settings → Environment Variables → Add DATABASE_URL for Production, Preview, and Development environments.

  3. 3

    Redeploy

    Trigger a new deployment. Check the build log — you should see ƒ next to the dynamic routes.

Validation

Navigate to a dynamic route URL in production. Returns the correct page content, not 404.

Verification Summary

Worked: 3
Partial: 1
Failed: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Product
Next.js + Vercel
Version
14.x
Environment
production

Submitted by

AC

Alex Chen

2450 rep

Tags

nextjsverceldynamic-routes404app-router