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.
29 changes: 29 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,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/');
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