mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
Merge pull request #47 from yangshun/fix-duplicate-redirect
Add check for unique redirect URLs
This commit is contained in:
@@ -28,6 +28,9 @@ exports.modifyWebpackConfig = ({config, stage}) => {
|
||||
exports.createPages = async ({graphql, boundActionCreators}) => {
|
||||
const {createPage, createRedirect} = boundActionCreators;
|
||||
|
||||
// Used to detect and prevent duplicate redirects
|
||||
const redirectToSlugMap = {};
|
||||
|
||||
const blogTemplate = resolve('./src/templates/blog.js');
|
||||
const communityTemplate = resolve('./src/templates/community.js');
|
||||
const docsTemplate = resolve('./src/templates/docs.js');
|
||||
@@ -114,13 +117,22 @@ exports.createPages = async ({graphql, boundActionCreators}) => {
|
||||
redirect = [redirect];
|
||||
}
|
||||
|
||||
redirect.forEach(fromPath =>
|
||||
redirect.forEach(fromPath => {
|
||||
if (redirectToSlugMap[fromPath] != null) {
|
||||
console.error(`Duplicate redirect detected from "${fromPath}" to:\n` +
|
||||
`* ${redirectToSlugMap[fromPath]}\n` +
|
||||
`* ${slug}\n`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
redirectToSlugMap[fromPath] = slug;
|
||||
createRedirect({
|
||||
fromPath: `/${fromPath}`,
|
||||
redirectInBrowser: true,
|
||||
toPath: `/${slug}`,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user