From 2f6411e708405f003006bfc682e3690043fba131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=A1ko=20Hevery?= Date: Fri, 8 Sep 2023 13:01:05 -0700 Subject: [PATCH] fix(qwik-city): Correctly SSG routes even with `trailingSlash: false` (#5132) Fix #4856 --- packages/qwik-city/adapters/shared/vite/post-build.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/qwik-city/adapters/shared/vite/post-build.ts b/packages/qwik-city/adapters/shared/vite/post-build.ts index a87476da21a..a7abef9c89f 100644 --- a/packages/qwik-city/adapters/shared/vite/post-build.ts +++ b/packages/qwik-city/adapters/shared/vite/post-build.ts @@ -11,10 +11,11 @@ export async function postBuild( ) { const ignorePathnames = new Set([basePathname + 'build/', basePathname + 'assets/']); - const staticPaths = new Set(userStaticPaths); + const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash)); const notFounds: string[][] = []; const loadItem = async (fsDir: string, fsName: string, pathname: string) => { + pathname = normalizeTrailingSlash(pathname); if (ignorePathnames.has(pathname)) { return; } @@ -62,6 +63,13 @@ export async function postBuild( }; } +function normalizeTrailingSlash(pathname: string) { + if (!pathname.endsWith('/')) { + return pathname + '/'; + } + return pathname; +} + function createNotFoundPathsModule(basePathname: string, notFounds: string[][], format: string) { notFounds.sort((a, b) => { if (a[0].length > b[0].length) {