Good Code
The good version lets the folder path define the route and reads the dynamic segment through the route props that Next.js provides.
Lesson 01
Use App Router folders and special files so routes match Next.js conventions.
export default async function ProjectPage({
params,
}: PageProps<"/projects/[projectId]">) {
// Route props keep dynamic segments typed and aligned with the folder path.
const { projectId } = await params;
return <h1>Project {projectId}</h1>;
}export default function ProjectsProjectIdPage() {
// Parsing the URL by hand bypasses App Router conventions and typing.
const projectId = window.location.pathname.split("/").at(-1);
return <h1>Project {projectId}</h1>;
}The good version lets the folder path define the route and reads the dynamic segment through the route props that Next.js provides.
The bad version invents a flat filename convention and parses the URL manually, which bypasses routing, typing, prerendering, and static params support.