admin管理员组

文章数量:1355532

I'm building a Next.js application using the App Router and I'm having trouble accessing route parameters from parent components that are higher in the routing hierarchy. My route structure:

app/page.tsx (Root page)

app/layout.tsx (Root layout)

app/[category]/page.js (Category-specific layout)

I need to access the [category] dynamic parameter from either app/page.tsx or app/layout.tsx`, which are strictly server components.

For example, if the user navigates to /products/electronics, I want to be able to access the value electronics in my root layout or page, but I'm not sure how to do this with server components since these parameters only exist when that segment of the URL is accessed.

本文标签: javascriptHow to access child route parameters from parent routes in Nextjs App RouterStack Overflow