Skip to content

Commit c068db2

Browse files
authored
fix: break out of layouts when falling back to root catch-all (#147)
1 parent ed5d4f6 commit c068db2

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/two-moles-fly.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv-router': patch
3+
---
4+
5+
Fix break out of layouts when falling back to root catch-all

src/helpers/match-route.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export function matchRoute(pathname, routes) {
6767
}
6868
if (breakFromLayouts) {
6969
routePart = `(${routePart})`;
70+
layouts = [];
7071
} else if ('layout' in routes && routes.layout) {
7172
layouts.push(routes.layout);
7273
}

tests/match-route.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,16 @@ describe('matchRoute', () => {
272272
expect(match).toEqual(PageNotFound);
273273
});
274274

275-
it('should not match any route', () => {
275+
it('should break out of layouts when falling back to root catch-all', () => {
276276
delete routes['*rest'];
277+
routes['(*rest)'] = PageNotFound;
278+
const { match, layouts } = matchRoute('/users/notfound', routes);
279+
expect(match).toEqual(PageNotFound);
280+
expect(layouts).toEqual([]);
281+
});
282+
283+
it('should not match any route', () => {
284+
delete routes['(*rest)'];
277285
const { match } = matchRoute('/notfound', routes);
278286
expect(match).toBeUndefined();
279287
});

0 commit comments

Comments
 (0)