Next.js Routing System
Routing
If you’re familar with next.js route system, you can skip this part and go ahead to the next part directly.
First, let’s take a look at the Next.js routing system.
In the app router of next.js, we could create folders under the app directory, and create page.tsx in these folders. For example:
- page.tsx
const DocumentsPage = () => {
return (
<div>
Documents Page
</div>
);
}
export default DocumentsPage;Then we can visit this page on http://localhost:3000/documents  and we’ll get
Documents Pageon the page.
Now let create another page under the documents folder:
- page.tsx
const DocumentIdPage = () => {
return (
<div>Document ID Page</div>
);
}
export default DocumentIdPage;Then we can visit this page on http://localhost:3000/documents/123  and we’ll get
Document ID Pageon the page.
It can be seen that the name of the folder we created will be parsed as a routing address by Next.js, and the page.tsx under the folder will be parsed as the content of the page corresponding to the routing address.
But what if we have a lot of documents with many different document ids? It is impossible to create folders and pages for every document! Don’t worry, Next.js’s dynamic routing system enables us to create countless routing pages with dynamic parameters.
Dynamic Routing
Let’s create a folder named [documentId] under documents directory, and write its page.tsx like this:
- page.tsx
interface DocumentIdPageProps {
params: Promise<{ documentId: string }>;
}
const DocumentIdPage = async ({ params }: DocumentIdPageProps) => {
const { documentId } = await params;
return (
<div>Document ID: { documentId }</div>
);
}
export default DocumentIdPage;The way to access params in Next.js 15 is a little bit different from that in Next.js 14. In Next.js 14, we could use params.documentId directly, but in Next.js 15, we should wait to get the params because it’s asynchronous now. You can refer to this document  to understand the principle behind it.
Now try to visit http://localhost:3000/documents/456  (you can change the 456 to any other characters you like), and you’ll get:
Document ID: 456on the browser.