Hello everybody,
I got this situation.
In my case the <head></head> scripts, and some SEO stuff are managed by the CMS, for example analytics scripts, ads scripts, and those scripts sometimes depends of the pathname criteria, like home, article, section etc. for example an article like "/news/the-future-of-ai" has some customs ads scripts and custom ld+json differents from the section like "/news"
So I have to place these services in root layout.js but I didn't find the way to get the pathname.
I tried placing the layout.js inside the "catch-all" route [...slug]/layout.js and get the params from the component arguments and It works, but for more than 300k articles get a nightmare for performance.
Of course, the entire route name "/news/the-future-of-ai" with the article and section, are also managed by the CMS. The headeless deliver the content type with the pathname query.
I also tried with headers injection in the middleware setting a custom header, something like x-pathname=/news/the-future-of-ai and then get the header in root layout by https://nextjs.org/docs/app/api-reference/functions/headers and it works, but
I'm using a self-hosted AWS server and the opennext lib doesn't fix that till v3 which I'm cosidering upgrade, buut jaja not now
So, I'm run out of ideas, if you handsome guy reading this post, maybe knows another way to get the pathname from the main root layout. I really appreciate your advice.
Regards