Capturing client side values when the app renders and using them server side.
Unanswered
Tonkinese posted this in #help-forum
TonkineseOP
Using next app router is there a way to capture client side values, like domain, site slug etc, and use them in server side components. A context won't work as a component needs to be a client to access the values and I don't want to pass the values as props as the components are heavily nested.
What are other people using to capture these values server side?
What are other people using to capture these values server side?
3 Replies
@Tonkinese Using next app router is there a way to capture client side values, like domain, site slug etc, and use them in server side components. A context won't work as a component needs to be a client to access the values and I don't want to pass the values as props as the components are heavily nested.
What are other people using to capture these values server side?
domain: environment variables, because you know the domain of your application
slug/path params: https://nextjs.org/docs/app/api-reference/file-conventions/page#params-optional
slug/path params: https://nextjs.org/docs/app/api-reference/file-conventions/page#params-optional
TonkineseOP
params are only available on that particular page. What if you want to get the site slug in a nested server component?
Use server-only-context in certain cases, impossible in others. https://nextjs-faq.com/get-pathname-in-rsc