diff --git a/.changeset/twenty-radios-camp.md b/.changeset/twenty-radios-camp.md new file mode 100644 index 00000000000..e00bf88178a --- /dev/null +++ b/.changeset/twenty-radios-camp.md @@ -0,0 +1,5 @@ +--- +'@builder.io/qwik-city': patch +--- + +fix: Multiple rewrite routes pointing to the same route is no longer an error. diff --git a/packages/qwik-city/src/buildtime/build-pages-rewrited.unit.ts b/packages/qwik-city/src/buildtime/build-pages-rewrited.unit.ts index 8f6875f5bed..8ae32d63361 100644 --- a/packages/qwik-city/src/buildtime/build-pages-rewrited.unit.ts +++ b/packages/qwik-city/src/buildtime/build-pages-rewrited.unit.ts @@ -228,3 +228,32 @@ testWithDuplicatedRoutes( assert.equal(r.pathname, '/produkt/'); } ); + +const testSameRoutes = testAppSuite('Same route with undefined prefixes', { + rewriteRoutes: [ + { + prefix: undefined, + paths: {}, + }, + { + prefix: undefined, + paths: { + produkt: 'produkt', + }, + }, + { + prefix: undefined, + paths: { + produkt: 'produkt', + }, + }, + ], +}); + +testSameRoutes( + 'Issue #6799: Bug while using rewrite routes pointing to the same file', + ({ assertRoute }) => { + const r = assertRoute('/produkt/'); + assert.equal(r.pathname, '/produkt/'); + } +); diff --git a/packages/qwik-city/src/buildtime/build.ts b/packages/qwik-city/src/buildtime/build.ts index 03951fa8789..16e450a20c7 100644 --- a/packages/qwik-city/src/buildtime/build.ts +++ b/packages/qwik-city/src/buildtime/build.ts @@ -78,7 +78,15 @@ function rewriteRoutes(ctx: BuildContext, resolvedFiles: ReturnType + item.pathname === routeToPush.pathname && item.routeName === routeToPush.routeName + ) + ) { + translatedRoutes.push(routeToPush); + } }); } });