You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

gatsby-plugin-contentstack-client-side-redirect

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-plugin-contentstack-client-side-redirect

Generates client side redirect html files for redirecting on any static site host like s3 or netlify.

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
47
38.24%
Maintainers
1
Weekly downloads
 
Created
Source

gatsby-plugin-contentstack-client-side-redirect

Generates client side redirect html files for redirecting on any static site host like s3 or netlify.

It uses window.location.href = url for redirection and createRedirect action provided by Gatsby

Install

npm install --save gatsby-plugin-contentstack-client-side-redirect

How to use

//  Register this plugin in gatsby-config.js
plugins: [
  `gatsby-plugin-contentstack-client-side-redirect`,
  `gatsby-plugin-client-side-redirect` // make sure to put last in the array
];

For contentstack specific only -

Steps -

  • Create a contenttype named as Redirects
  • Create a group named as urls_mapping inside Redirects contenttype
  • Create two text fields as old_url and new_url and save it
  • Now enter pairs of old and new urls for redirection!

Have a look at the code if you are interested :)

const response = await graphql(`
query redirects {
  allContentstackRedirects {
    edges {
      node {
        urls_mapping {
          old_url
          new_url
        }
      }
    }
  }
}`)

const allEntries = response.data.allContentstackRedirects.edges
let urls

if (allEntries)
{
  allEntries.forEach(entry => {
    urls = entry.node.urls_mapping

    if (urls)
    {
      createRedirect({ fromPath: urls.old_url, toPath: urls.new_url, isPermanent: true })
    }
  })
}

Keywords

gatsby

FAQs

Package last updated on 25 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts