1
0
mirror of https://github.com/kremalicious/gatsby-redirect-from.git synced 2024-06-17 01:43:21 +02:00
This commit is contained in:
Matthias Kretschmann 2020-02-20 09:11:22 +01:00 committed by GitHub
commit e695b23899
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,17 +45,28 @@ export function createPages({ graphql, actions }, pluginOptions) {
})
})
const createRedirectTemplate = (from, to) => {
createRedirect({
fromPath: from,
toPath: to,
isPermanent: true,
redirectInBrowser: true
})
}
// Create redirects from the just constructed array
redirects.forEach(({ from, to }) => {
// iterate through all `from` array items
from.forEach(from => {
createRedirect({
fromPath: from,
toPath: to,
isPermanent: true,
redirectInBrowser: true
// `from` is a string when only a single value is set
if (typeof 'string' === from) {
createRedirectTemplate(from, to)
}
// otherwise `from` is a list array
else {
// iterate through all `from` array items
from.forEach(from => {
createRedirectTemplate(from, to)
})
})
}
})
resolve(