From 6f7a9c201077ef948b99c245c1449a93e2eedb2a Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 10 Nov 2023 12:02:55 +0000 Subject: [PATCH] fix(@angular-devkit/build-angular): prerender default view when no routes are defined Prior to the commit, when no routes were defined the default view was not prerendering. Closes #26317 --- .../src/utils/routes-extractor/extractor.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/utils/routes-extractor/extractor.ts b/packages/angular_devkit/build_angular/src/utils/routes-extractor/extractor.ts index 5e4ecdfef35e..6c6d442e5634 100644 --- a/packages/angular_devkit/build_angular/src/utils/routes-extractor/extractor.ts +++ b/packages/angular_devkit/build_angular/src/utils/routes-extractor/extractor.ts @@ -117,10 +117,15 @@ export async function* extractRoutes( const injector = applicationRef.injector; const router = injector.get(Router); - const compiler = injector.get(Compiler); - // Extract all the routes from the config. - yield* getRoutesFromRouterConfig(router.config, compiler, injector); + if (router.config.length === 0) { + // In case there are no routes available + yield { route: '', success: true, redirect: false }; + } else { + const compiler = injector.get(Compiler); + // Extract all the routes from the config. + yield* getRoutesFromRouterConfig(router.config, compiler, injector); + } } finally { platformRef.destroy(); }