Next.js Discord

Discord Forum

Is it possible to fetch params within a server component when using app router?

Unanswered
Sloth bear posted this in #help-forum
Open in Discord
Sloth bearOP
I am generating all route paths during build(export) time. We can access the url params in /[id]/page.tsx in the params prop as well as in the layout.tsx file . Is there any way i can fetch url params within a server component that is used within the page.

17 Replies

the page.js gets Params as Props
Sloth bearOP
yea, is there any way without passing as props from page to server components. I want to be able to access the params directly within the server component
Sadly, I think there is no method without prop-drilling
Server-side state management solution does not exist currently (as far as I know)
Sloth bearOP
do you mean params from the prop? i cannot access params within a server component
Beveren
What happens when you try to fetch() the ${id} from the component?
@Sloth bear do you mean params from the prop? i cannot access params within a server component
Horse guard wasp
so your server component is not a page....if its a page its possible
Sloth bearOP
yes
@Beveren What happens when you try to fetch() the ${id} from the component?
Sloth bearOP
where can i get id from ?
Beveren
your /app/[id]/page.tsx
@Beveren your /app/[id]/page.tsx
Sloth bearOP
I want to access the id within a server component that is used in Page.tsx. I was wondering if there is a way to do this without passing it as a prop
Beveren
what's wrong with prop passing?
Sloth bearOP
My application renders dynamic components from a CMS system. i wish to do data fetching in some components only which requires access to url param. the component names etc are not known before hand, its known at build time, so i have an interface <DynamicComponent/> which can be anything. so i do not want to pass the prop to all components.
Beveren
you import a component from somewhere that fetch()s the id and you const id = component() the thing in your page ?
oh, word