Is setting document.title really the best solution for a dynamic title in app router?
Unanswered
Thai posted this in #help-forum
ThaiOP
We're using the app router, and deep in the client code, we determine the title for the page. The user can also change the title. Ideally we would be able to set it here with a <Title> tag.
Instead it seems like people are suggesting using
Setting
Instead it seems like people are suggesting using
document.title? Notably, we cannot use generateMetadata as the title will change, and we can only load the data on the client side.Setting
document.title seems a bit fraught with errors, as you could run into issues when navigation is happening and different pages are setting to the title simultaneously.1 Reply
Kokoni
In this case I'd make a component called Title that has a useEffect(() => document.title = props.children, [props.children])