tizmagik / react-head

⛑ SSR-ready Document Head tag management for React 16+
MIT License
323 stars 34 forks source link

Link canonical cascade #101

Open simonpetry opened 4 years ago

simonpetry commented 4 years ago

First off, love the lib. Would there be some merit to cascading a <link rel="canonical" ... /> tag? (link tags aren't cascaded and for good reason)

But this particular link tag has a uniqueness requirement akin to title and other meta tags, Multiple canonicals are ignored (this is old, but looks to be still relevant)

Specify no more than one rel=canonical for a page. When more than one is specified, all rel=canonicals will be ignored.

To bring this to a question: right now canonical is required to be set on every page, but should this be handled as an edge case and cascaded, or maybe there something a little more interesting here where we can leverage the platform and give any link tag the ability to cascade given a unique identifier via an id or class (or other) attribute?

One last thing, the canonical tag in the readme is using a content attribute but I think you want an href attribute: <Link rel="canonical" content="http://jeremygayed.com/" /> to <Link rel="canonical" href="http://jeremygayed.com/" />

Thank you for you time

tizmagik commented 4 years ago

Interesting! What would a cascading a Link canonical look like? Would we just append them down the tree? 🤔

I guess we could support something like this by tweaking the cascade list here:

https://github.com/tizmagik/react-head/blob/47393b4dc7ca99d53e4d64e1167a119e0860437c/src/HeadProvider.js#L4

Although it would need to be slightly more sophisticated than that if we only want to cascade <Link rel="canonical" /> and not other Link tags. But I'm curious to understand your use case a bit better.