如何更新 React.js 中的元标记? [英] How to update meta tags in React.js?

查看:42
本文介绍了如何更新 React.js 中的元标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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?

推荐答案

我用过 旧项目中的 react-document-meta.

只需定义您的元值

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'
        }
    }

并放置一个

<DocumentMeta {...meta} />

在返回

这篇关于如何更新 React.js 中的元标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆