Skip to content

Commit ab1736a

Browse files
added redirect logic
Signed-off-by: Rajesh-Nagarajan-11 <rajeshnagarajan36@gmail.com>
1 parent d415a34 commit ab1736a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

gatsby-node.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
470470

471471
handbook.forEach((page) => {
472472
let finalSlug = page.fields.slug;
473+
// Strip `.html` for production builds so client-side router matches clean paths
473474
if (process.env.NODE_ENV === "production") {
474475
finalSlug = finalSlug.replace(/\.html$/, "");
475476
}
@@ -481,6 +482,17 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
481482
slug: finalSlug,
482483
},
483484
});
485+
486+
// If the source slug contained .html, create a redirect so .html URLs still resolve
487+
if (finalSlug !== page.fields.slug) {
488+
createRedirect({
489+
fromPath: page.fields.slug,
490+
toPath: finalSlug,
491+
isPermanent: true,
492+
redirectInBrowser: true,
493+
force: true,
494+
});
495+
}
484496
});
485497

486498

0 commit comments

Comments
 (0)