Gatsby Meta Refresh Redirect Plugin

1.1.1 · abandoned · verified Tue Apr 21

gatsby-plugin-meta-redirect is a Gatsby plugin designed to generate static HTML files containing a `<meta http-equiv="refresh">` tag. This enables client-side redirects on any static file host, such as S3 or Netlify, without requiring server-side redirect rules or `.htaccess` configurations. The plugin processes `createRedirect` actions called within Gatsby's Node API (e.g., in `gatsby-node.js`) and outputs an `index.html` file at the `fromPath` containing the meta refresh tag pointing to the `toPath`. Currently at version 1.1.1, the package has not seen updates in over seven years, indicating an abandoned maintenance schedule. Its primary differentiator is the universal compatibility across static hosts, but this comes with SEO and user experience trade-offs compared to server-side 301 redirects.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure `gatsby-plugin-meta-redirect` in `gatsby-config.js` and how to define redirects using Gatsby's `createRedirect` action within `gatsby-node.js` for both static and data-driven redirect scenarios. It illustrates basic permanent redirects, language-specific redirects, and iterating over markdown frontmatter to generate redirects programmatically.

// gatsby-config.js
module.exports = {
  plugins: [
    // Ensure this plugin is the last one in your array
    `gatsby-plugin-meta-redirect`
  ]
};

// gatsby-node.js
const path = require('path');

exports.createPages = async ({ actions, graphql }) => {
  const { createRedirect, createPage } = actions;

  // Example 1: Basic permanent redirect
  createRedirect({
    fromPath: '/legacy-page/',
    toPath: '/new-destination/',
    isPermanent: true,
    redirectInBrowser: true
  });

  // Example 2: Redirect with a language preference
  createRedirect({
    fromPath: '/global-content/',
    toPath: '/en-US/global-content/',
    Language: 'en'
  });

  // Example 3: Programmatic redirect based on data (e.g., old blog post slugs)
  const result = await graphql(`
    {
      allMarkdownRemark {
        edges {
          node {
            frontmatter {
              slug
              oldPaths
            }
          }
        }
      }
    }
  `);

  if (result.errors) {
    throw result.errors;
  }

  const posts = result.data.allMarkdownRemark.edges;

  posts.forEach(({ node }) => {
    if (node.frontmatter.oldPaths) {
      node.frontmatter.oldPaths.forEach(oldPath => {
        createRedirect({
          fromPath: oldPath,
          toPath: node.frontmatter.slug,
          isPermanent: true,
          redirectInBrowser: true
        });
      });
    }
    createPage({
      path: node.frontmatter.slug,
      component: path.resolve('./src/templates/blog-post.js'),
      context: {
        slug: node.frontmatter.slug,
      },
    });
  });
};

view raw JSON →