Next.js Discord

Discord Forum

Routing Question

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Avatar
Transvaal lionOP
I am creating an application with multiple calculators and have a header that is shared across the parent layout of the /calculators folder that needs to know which calculator is currently being used to generate a title dynamically. The folder structure is structured like so...

/calculators (folder)
/calculator-1
calculator.tsx
page.tsx
/calculator-2
calculator.tsx
page.tsx
layout.tsx
page.tsx

I am currently not using any brackets, quotes, ellipsis, etc. Is there an easy way to get the current calculator to update the header? Attempting to get params returns undefined/null since none of the folders are bracketed. Any help would be super appreciated.

5 Replies

Avatar
Burmese
There is no reason you couldn't make /calculators/layout.tsx take a client component that updates when the user selects their calculator.
Avatar
risky
Other than the fact that you shouldn't make a layout a client component because of the amount of things that won't work well (ie metadata)
Also you can have server component layout and just import client component into it (and use usePathname to know which page you are on)
Avatar
Burmese
This is exactly what I am saying.
Oh, I mean the layout would just take some client component, not be a client component. Calc type can get passed in via the url.