From 3580099bb18c1774c99d0eb084fde6b4e9569842 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 30 Aug 2018 13:35:34 +0200 Subject: [PATCH] handle string value --- src/gatsby-node.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/gatsby-node.js b/src/gatsby-node.js index 911b125..be576ba 100644 --- a/src/gatsby-node.js +++ b/src/gatsby-node.js @@ -43,17 +43,28 @@ export function createPages({ graphql, actions }) { }) }) + 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(