📜  gatsby-plugin-react-helmet-canonical-urls (1)

📅  最后修改于: 2023-12-03 15:15:13.525000             🧑  作者: Mango

Gatsby Plugin React Helmet Canonical URLs

Gatsby Plugin React Helmet Canonical URLs is a plugin for GatsbyJS that adds a canonical URL meta tag to the head of each page using the React Helmet library. This meta tag indicates the preferred URL for a page and is beneficial for search engine optimization (SEO) purposes.

Installation

To install Gatsby Plugin React Helmet Canonical URLs, use the package manager npm:

npm install --save gatsby-plugin-react-helmet-canonical-urls
Usage

To use Gatsby Plugin React Helmet Canonical URLs, add it to the plugins array in your gatsby-config.js file:

module.exports = {
  plugins: [
    `gatsby-plugin-react-helmet-canonical-urls`,
    // other plugins
  ],
}
Configuration

By default, the plugin uses the siteUrl from your siteMetadata in gatsby-config.js as the base URL for the canonical URL. You can also specify a specific URL for a page by adding a canonical property to the frontmatter of a Markdown file:

---
title: My Page
date: 2022-01-01
canonical: https://example.com/my-page/
---
Output

When the plugin is added to your site, it will automatically add a canonical URL meta tag to the head of each page:

<head>
  <!-- other meta tags -->
  <link rel="canonical" href="https://example.com/my-page/" />
</head>

This tag indicates the preferred URL for the page and can help search engines understand the content on your site.