Next.js Discord

Discord Forum

Get URL path in server component where all paths are known at build time?

Unanswered
Argente Brun posted this in #help-forum
Open in Discord
Argente BrunOP
Hi all, I'm building a breadcrumb component and I'm wondering what data fetching approach I should be using.

It's an SSG site using the App router. I'm using dynamic routes but with static params, so all paths will be known at build time.

Am I wrong in thinking this ought to be done with server components? I know I can't use usePathname() which I understand is informed by the client-side router, but is there a server-side alternative considering the paths are known ahead of time? Is this a limitation in Next or am I misunderstanding something?

The only workaround I can think of is to use a single dynamic route at [[...slug]]/page.tsx, so that the params prop contains all sections of the url. Then prop drill that down to child components.

2 Replies

Argente BrunOP
or do some setup in generateStaticParams() to preload some data to be used later in the breadcrumb component
Argente BrunOP
Bump 🙂