Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update meta tags in React.js?

Tags:

reactjs

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?

like image 612
Harkirat Saluja Avatar asked Jun 09 '16 18:06

Harkirat Saluja


People also ask

Can you do MVC in react?

React isn't an MVC framework. React is a library for building composable user interfaces. While this is true, the term MVC framework is more of a marketing term. The original MVC concept is closer to a design pattern and has nothing to do with frameworks.


1 Answers

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

like image 164
KRONWALLED Avatar answered Oct 01 '22 11:10

KRONWALLED