Skip to content

Commit

Permalink
fix(@angular/ssr): use wildcard server route configuration on the '/'…
Browse files Browse the repository at this point in the history
… route when the app router is empty

(cherry picked from commit d3dd8f0)
  • Loading branch information
dgp1130 committed Nov 18, 2024
1 parent 4b4e000 commit fb05e7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 7 additions & 2 deletions packages/angular/ssr/src/routes/ng-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,16 @@ export async function getRoutesFromAngularRouterConfig(
}
}
} else {
const renderMode = serverConfigRouteTree?.match('')?.renderMode ?? RenderMode.Prerender;
const rootRouteMetadata = serverConfigRouteTree?.match('') ?? {
route: '',
renderMode: RenderMode.Prerender,
};

routesResults.push({
...rootRouteMetadata,
// Matched route might be `/*` or `/**`, which would make Angular serve all routes rather than just `/`.
// So we limit to just `/` for the empty app router case.
route: '',
renderMode,
});
}

Expand Down
8 changes: 5 additions & 3 deletions packages/angular/ssr/test/routes/ng-routes_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ describe('extractRoutesAndCreateRouteTree', () => {
);
});

it('should apply RenderMode matching the wildcard when no Angular routes are defined', async () => {
setAngularAppTestingManifest([], [{ path: '**', renderMode: RenderMode.Server }]);
it('should use wildcard configuration when no Angular routes are defined', async () => {
setAngularAppTestingManifest([], [{ path: '**', renderMode: RenderMode.Server, status: 201 }]);

const { errors, routeTree } = await extractRoutesAndCreateRouteTree(
url,
Expand All @@ -351,6 +351,8 @@ describe('extractRoutesAndCreateRouteTree', () => {
);

expect(errors).toHaveSize(0);
expect(routeTree.toObject()).toEqual([{ route: '/', renderMode: RenderMode.Server }]);
expect(routeTree.toObject()).toEqual([
{ route: '/', renderMode: RenderMode.Server, status: 201 },
]);
});
});

0 comments on commit fb05e7f

Please sign in to comment.