I was working on a single page application in react.js, so what is the best way to update meta tags on page transitions or browser back/forward?
相关问题
- How to toggle on Order in ReactJS
- Refreshing page gives Cannot GET /page_url in reac
- Adding a timeout to a render function in ReactJS
- React Native Inline style for multiple Text in sin
- Issue with React.PropTypes.func.isRequired
相关文章
- Why would we use useEffect without a dependency ar
- Is it possible to get ref of props.children?
- Stateless function components cannot be given refs
- React testing library: Test attribute / prop
- React/JestJS/Enzyme: How to test for ref function?
- Material-UI [v0.x] RaisedButton on hover styles
- Remove expo from react native
- ReactJS toLowerCase is not a function
According to the official documentation React Doc - Title and Meta Tags, you can also use React Helmet
You can use react-meta-tags. It allows you to write title and other meta tags in a declarative way and in normal jsx format, which will be moved to head (Check server usage on the doc).
You may also like to check react-helmet if you have an advanced use case.
I've used react-document-meta in an older project.
Just define your meta values
and place a
in the return
It is mentioned in other answers and comments, but it deserves highlighting - You almost definitely want to use:
React Helmet
This seems to be the solution that the community almost exclusively uses - 600,000 weekly downloads vs the 6,000 given in other solutions. "Helmet takes plain HTML tags and outputs plain HTML tags. It's dead simple, and React beginner friendly." - and has support for server-side rendering.
Nice and very straightforward React Helmet usage example here:
https://dev.to/guimg/dynamic-document-head-with-react-helmet-28o6
The simple idea is you can use
<Helmet></Helmet>
component blocks to change your meta tags in accordance with your dynamic/internal pages content, like:You cand also give the page title and meta tags description in the following way.
place a meta tag of description in your index.html file like this.
in your .js files or .jsx files below the render() method write the page title and meta description for the page like this .