404 | This page could not be found.
Next.js canβt find the page youβre trying to access.
Fix 1: Check file location (App Router)
In the App Router, every page needs a page.tsx file inside a folder:
app/
page.tsx β /
about/page.tsx β /about β
about.tsx β nothing β (no page.tsx)
blog/[slug]/page.tsx β /blog/my-post β
Fix 2: Check file location (Pages Router)
In the Pages Router, the file name IS the route:
pages/
index.tsx β /
about.tsx β /about β
blog/[slug].tsx β /blog/my-post β
Fix 3: Restart the dev server
After adding new files, sometimes the dev server doesnβt pick them up:
# Kill the server (Ctrl+C) and restart
npm run dev
Fix 4: Check dynamic routes
// app/blog/[slug]/page.tsx
// Make sure generateStaticParams returns the right slugs
export async function generateStaticParams() {
const posts = await getPosts();
return posts.map(post => ({ slug: post.slug }));
}
If a slug isnβt in generateStaticParams and youβre using output: 'export' (static), that page wonβt exist.
Fix 5: Check for trailing slashes
// next.config.js
module.exports = {
trailingSlash: true, // /about/ instead of /about
};
If trailingSlash is enabled, /about returns 404 but /about/ works (and vice versa).
Fix 6: Build and check
npm run build
# Look at the output β it lists all generated pages
# If your page isn't listed, it won't work in production
See also: Next.js cheat sheet | Vercel build failed fix
Related: What is Next.js Β· React Interview Questions Β· When To Use Ssr Vs Ssg Vs Spa