Accessing pathname in NextJS generateMetadata

Can't access the router in generateMetadata, and using params is inadequate if you need the actual path. Guess we have to pass it through from middleware.

Next.js Discussions suggested invoking set directly on request.headers but that was returning null in generateMetadata.

Had better success modifying the NextResponse.rewrite as documented in this Vercel demo.

Example below:

Published September 10, 2023