Harkirat Saluja Harkirat Saluja - 2 months ago 36
React JSX Question

How to update meta tags in React.js?

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?

Answer

I've used react-document-meta in an older project.

Just define your meta values

const meta = {
    title: 'Some Meta Title',
    description: 'I am a description, and I can create multiple tags',
    canonical: 'http://example.com/path/to/page',
    meta: {
        charset: 'utf-8',
        name: {
            keywords: 'react,meta,document,html,tags'
        }
    }

and place a

<DocumentMeta {...meta} />

in the return

Comments