Skip to content

Commit da725e9

Browse files
JerryWu1234wuls
andauthored
6799 fix route (#6970)
Co-authored-by: wuls <[email protected]>
1 parent e3379dd commit da725e9

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

.changeset/twenty-radios-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@builder.io/qwik-city': patch
3+
---
4+
5+
fix: Multiple rewrite routes pointing to the same route is no longer an error.

packages/qwik-city/src/buildtime/build-pages-rewrited.unit.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,32 @@ testWithDuplicatedRoutes(
228228
assert.equal(r.pathname, '/produkt/');
229229
}
230230
);
231+
232+
const testSameRoutes = testAppSuite('Same route with undefined prefixes', {
233+
rewriteRoutes: [
234+
{
235+
prefix: undefined,
236+
paths: {},
237+
},
238+
{
239+
prefix: undefined,
240+
paths: {
241+
produkt: 'produkt',
242+
},
243+
},
244+
{
245+
prefix: undefined,
246+
paths: {
247+
produkt: 'produkt',
248+
},
249+
},
250+
],
251+
});
252+
253+
testSameRoutes(
254+
'Issue #6799: Bug while using rewrite routes pointing to the same file',
255+
({ assertRoute }) => {
256+
const r = assertRoute('/produkt/');
257+
assert.equal(r.pathname, '/produkt/');
258+
}
259+
);

packages/qwik-city/src/buildtime/build.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ function rewriteRoutes(ctx: BuildContext, resolvedFiles: ReturnType<typeof resol
7878
return;
7979
}
8080
const routeToPush = translateRoute(route, config, configIndex);
81-
translatedRoutes.push(routeToPush);
81+
82+
if (
83+
!translatedRoutes.some(
84+
(item) =>
85+
item.pathname === routeToPush.pathname && item.routeName === routeToPush.routeName
86+
)
87+
) {
88+
translatedRoutes.push(routeToPush);
89+
}
8290
});
8391
}
8492
});

0 commit comments

Comments
 (0)