Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6799 fix route #6970

Merged
merged 15 commits into from
Nov 4, 2024
5 changes: 5 additions & 0 deletions .changeset/twenty-radios-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik-city': major
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
---

fix: a bug while using rewrite routes pointing to the same file
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 30 additions & 0 deletions packages/qwik-city/src/buildtime/build-pages-rewrited.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,33 @@ testWithDuplicatedRoutes(
assert.equal(r.pathname, '/produkt/');
}
);

const testWithDuplicate = testAppSuite('ssss', {
rewriteRoutes: [
{
prefix: undefined,
paths: {},
},
{
prefix: undefined,
paths: {
produkt: 'produkt',
},
},
{
prefix: undefined,
paths: {
booking: 'reservation',
},
},
],
});

testWithDuplicate(
'Issue #6799: Bug while using rewrite routes pointing to the same file',
({ assertRoute }) => {
const r = assertRoute('/produkt/');
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved

assert.equal(r.pathname, '/produkt/');
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
}
);
10 changes: 9 additions & 1 deletion packages/qwik-city/src/buildtime/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ function rewriteRoutes(ctx: BuildContext, resolvedFiles: ReturnType<typeof resol
return;
}
const routeToPush = translateRoute(route, config, configIndex);
translatedRoutes.push(routeToPush);

if (
!translatedRoutes.some(
(item) =>
item.pathname === routeToPush.pathname && item.routeName === routeToPush.routeName
)
) {
translatedRoutes.push(routeToPush);
}
});
}
});
Expand Down