Note: This is a question, and not an issue. Please close it if this isn't the appropriate place for it.
Question: Can you recommend a way to maintain the page title with react-router?
We discussed this in #107, but I don't think we ever actually figured out a "recommended" solution.
We're currently passing both state and props to a static getMetaData method that returns title and other metadata such as OpenGraph tags. This is then used in componentDidUpdate so we're sure any changes are reflected in the title at all times, this works especially well when your title might be dependent on data that might arrive in chunks.
I should put some code up on github. Here's how I handle it:
Constraints:
Method:
I make a title module that:
Its pretty much how a react component works, except it doesn't work on the dom, it sets document.title.
Since lots of people are asking about this, maybe we could just make a module like you're describing and distribute it with the router? It's not totally out of scope..
If you were going to do that, would it also make sense to allow specifying <meta> as well? Or basically anything that exists within <head />?
my module just outputs to document.title, its not actually a component or anything. It just sort of acts like one.
But ... we may want some fancy business with anything in <head/> for server-side rendering I think.
@rpflorence Definitely, you'll probably want various meta-tags for Twitterbook and Myface
SEO ALL THE THINGS!
Haven't used yet but adding for posterity's sake: react-document-title looks promising and seems like it could be a nice little addition to Route.props :+1:
Obviously, this is easy for me to say since I'm not a project maintainer :)
react-document-title is good, though it would be better to support SEO titles in react-router since react-document-title just duplicates its hierarchy. SEO title is a navigational aspect and can be lifted to router IMO.
I probably subliminally got the idea from this thread and later forgot about it.
Ivan, your point makes a lot of sense to me
I think it's best left in userland though. It's trivial to make a function to wrap your route handlers into react-document-title or whatever else comes along.
Anything new here? I'm banging my head against the wall because of this ;) (doing server-side rendering).
^I'm wondering the same thing as well. As of now I've yet to find a solution for rendering route-specific meta tags on the server.
@jaraquistain try https://github.com/gaearon/react-side-effect
It was created for such tasks
@ivan-kleshnin Thanks for the tip, I'll check it out
React helmet is great! Check it out https://github.com/nfl/react-helmet
I second react-helmet, I actually ended up using that in my implementation
Most helpful comment
React helmet is great! Check it out https://github.com/nfl/react-helmet