diff --git a/packages/kit/src/core/adapt/prerender.js b/packages/kit/src/core/adapt/prerender.js index 831cb64b0ae21..5db32efe9c8c2 100644 --- a/packages/kit/src/core/adapt/prerender.js +++ b/packages/kit/src/core/adapt/prerender.js @@ -90,11 +90,26 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a } }); + /** + * @param {string} path + */ + function normalizeTrailingSlash(path) { + if (config.kit.trailingSlash === 'always') { + return path.endsWith('/') ? path : `${path}/`; + } + if (config.kit.trailingSlash === 'never') { + return !path.endsWith('/') || path === '/' ? path : path.slice(0, -1); + } + return path; + } + /** * @param {string} path * @param {string} parent */ async function visit(path, parent) { + path = normalizeTrailingSlash(path); + if (seen.has(path)) return; seen.add(path);