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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
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': patch
---

fix: Multiple rewrite routes pointing to the same route is no longer an error.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
"tsc.trace": "tsc -p tsconfig.json --traceResolution > tsc.log",
"tsc.watch": "tsc --noEmit --watch --preserveWatchOutput",
"update.qwik.builds": "tsm scripts/update-qwik-builds.ts packages/docs && tsm scripts/update-qwik-builds.ts packages/insights; pnpm install",
"vitest": "vitest"
"vitest": "vitest run build-pages-rewrited.unit"
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
},
"simple-git-hooks": {
"pre-commit": "pnpm pretty-quick --staged"
Expand Down
36 changes: 36 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,39 @@ testWithDuplicatedRoutes(
assert.equal(r.pathname, '/produkt/');
}
);

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

testSameRoutes(
'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/');
}
);
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
Loading