Skip to content

Commit

Permalink
Fix rendering of nested fallback routes
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonmade committed Aug 5, 2024
1 parent 3a200ab commit d91c56d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-donuts-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@quilted/preact-router': patch
---

Fix rendering of nested fallback routes
4 changes: 2 additions & 2 deletions packages/preact-router/source/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ export class RouterNavigationCache {
}

const keyID = typeof key === 'string' ? key : JSON.stringify(key);
const loadID = parent?.consumed ? `${parent.consumed}:${keyID}` : keyID;
const id = `${matchID}:${keyID}`;
const loadID = parent?.key ? `${parent.key}:${keyID}` : keyID;
const id = `${matchID}:${loadID}`;

let entry = entryCache.get(id);
if (entry == null) {
Expand Down
18 changes: 18 additions & 0 deletions packages/preact-router/source/tests/e2e.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,24 @@ describe('useRoutes()', () => {
expect(routes).toContainPreactComponent(RouteComponent);
});

it('matches a nested fallback routes', () => {
function Routes() {
return useRoutes([
{
match: '*',
render: <RouteComponent />,
children: [{render: <NestedRouteComponent />}],
},
]);
}

const routes = render(<Routes />, {path: '/foo/bar'});

console.log(routes.debug());

expect(routes).toContainPreactComponent(NestedRouteComponent);
});

it('does not consume the matched pathname when there is no match property', () => {
function Routes() {
return useRoutes([
Expand Down

0 comments on commit d91c56d

Please sign in to comment.