1
0
mirror of https://github.com/kremalicious/gatsby-redirect-from.git synced 2024-07-01 06:01:51 +02:00

handle string value

This commit is contained in:
Matthias Kretschmann 2018-08-30 13:35:34 +02:00
parent 416354bf00
commit 3580099bb1
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -43,17 +43,28 @@ export function createPages({ graphql, actions }) {
}) })
}) })
// Create redirects from the just constructed array const createRedirectTemplate = (from, to) => {
redirects.forEach(({ from, to }) => {
// iterate through all `from` array items
from.forEach(from => {
createRedirect({ createRedirect({
fromPath: from, fromPath: from,
toPath: to, toPath: to,
isPermanent: true, isPermanent: true,
redirectInBrowser: true redirectInBrowser: true
}) })
}
// Create redirects from the just constructed array
redirects.forEach(({ from, to }) => {
// `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( resolve(