Next.js Discord

Discord Forum

How can I get the current route in the Template or Layout file?

Answered
Satin Angora posted this in #help-forum
Open in Discord
Satin AngoraOP
I want my application to utilize server components as much as possible, but for a segment in the project, there is a bit of shared layout; so I want to use layout or template file.
But I am not sure about how to get the current route, to support it to one of the components inside shared layout.
Also should I use template or layout for this shared layout? Reading on documents, I think for this use case template is more appropriate.

Any pointers is appreciated! ^.^
Answered by riský
The issue for layout is that it isn't rerendered for different routes, so you would need to import a client component with usePathname into the layout
View full answer

2 Replies

The issue for layout is that it isn't rerendered for different routes, so you would need to import a client component with usePathname into the layout
Answer
Satin AngoraOP
TY for informing me.