I recently upgraded to Next.js 15, and I'm facing an issue when trying to access params in a dynamic route.
Folder structure:
/app
/product
/[id]
/page.tsx
When I try to access the id from params in my [id]/page.tsx, I get this error:
A param property was accessed directly with
params.id.paramsis now a Promise and should be unwrapped withReact.use()before accessing properties of the underlying params object. In this version of Next.js direct access to param properties is still supported to facilitate migration, but in a future version, you will be required to unwrapparamswithReact.use().
app/product/[id]/page.tsx):
export default async function Page({ params }: { params: { id: string } }) {
const id = params.id; // This throws the error
return <div>Product ID: {id}</div>;
}
I tried changing the function signature to this:
export default async function Page({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
return <div>Product ID: {id}</div>;
}
This works, but I'm unsure if it's the correct approach.
I reviewed the Next.js 15 documentation, but there's no clear mention of this behavior change.
Questions:
- Is this the correct way to handle
paramsin Next.js 15? - Why is
paramsnow aPromise, and is this an intentional breaking change for future versions?