简体   繁体   中英

next.js Head imported from next/head doesn't work properly on share pages

I've migrated from create-react-app to create-next-app to my website, but the Head(app/head) component isn't working properly

Assuming I have a blog, and in pages, I have the following structure: pages/blog/index.js, pages/blog/[slug].js. In [slug].js, I'm using the Head component so it takes the title of the blog post: <Head><title>{post.title}</title></Head> The problem is that when using react-share on the blog post it doesn't put the right title, even when I do an inspect element on the page, I can see the right Head values, but the Facebook debug ( https://developers.facebook.com/tools/debug/ ) tool doesn't recognize the right title.

Any help will be used. thanks, guys

the answer is that you should bring data via getInitialProps so it can accessible to component and not via useEffect:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM