Skip to content

Commit 27a3b98

Browse files
authored
Merge pull request reactjs#194 from emmafallancy/fix-blog-slug-html-creation
Fix the blog slug html creation that leads to improper redirect
2 parents c3b24ff + 331fd30 commit 27a3b98

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

gatsby-node.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,16 @@ exports.createPages = async ({graphql, boundActionCreators}) => {
124124
process.exit(1);
125125
}
126126

127+
// A leading "/" is required for redirects to work,
128+
// But multiple leading "/" will break redirects.
129+
// For more context see github.com/reactjs/reactjs.org/pull/194
130+
const toPath = slug.startsWith('/') ? slug : `/${slug}`;
131+
127132
redirectToSlugMap[fromPath] = slug;
128133
createRedirect({
129134
fromPath: `/${fromPath}`,
130135
redirectInBrowser: true,
131-
toPath: `/${slug}`,
136+
toPath,
132137
});
133138
});
134139
}

0 commit comments

Comments
 (0)