Browse Source

Merge pull request #194 from emmafallancy/fix-blog-slug-html-creation

Fix the blog slug html creation that leads to improper redirect
main
Brian Vaughn 7 years ago
committed by GitHub
parent
commit
27a3b98fb5
  1. 7
      gatsby-node.js

7
gatsby-node.js

@ -124,11 +124,16 @@ exports.createPages = async ({graphql, boundActionCreators}) => {
process.exit(1); process.exit(1);
} }
// A leading "/" is required for redirects to work,
// But multiple leading "/" will break redirects.
// For more context see github.com/reactjs/reactjs.org/pull/194
const toPath = slug.startsWith('/') ? slug : `/${slug}`;
redirectToSlugMap[fromPath] = slug; redirectToSlugMap[fromPath] = slug;
createRedirect({ createRedirect({
fromPath: `/${fromPath}`, fromPath: `/${fromPath}`,
redirectInBrowser: true, redirectInBrowser: true,
toPath: `/${slug}`, toPath,
}); });
}); });
} }

Loading…
Cancel
Save