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
plugins: [
`gatsby-plugin-contentstack-client-side-redirect`,
`gatsby-plugin-client-side-redirect`
];
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 })
}
})
}