Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/angular/ssr/src/utils/ng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import { addTrailingSlash, joinUrlParts, stripIndexHtmlFromURL, stripTrailingSla
* - A function that returns a `Promise<ApplicationRef>`, which resolves with the root application reference.
*/
export type AngularBootstrap =
| Type<unknown>
| ((context: BootstrapContext) => Promise<ApplicationRef>);
Type<unknown> | ((context: BootstrapContext) => Promise<ApplicationRef>);

/**
* Renders an Angular application or module to an HTML string.
Expand Down Expand Up @@ -111,13 +110,13 @@ export async function renderAngular(

// TODO(alanagius): Find a way to avoid rendering here especially for redirects as any output will be discarded.
const envInjector = applicationRef.injector;
const routerIsProvided = !!envInjector.get(ActivatedRoute, null);
const router = envInjector.get(Router);
const lastSuccessfulNavigation = router.lastSuccessfulNavigation();
const router = envInjector.get(Router, null, { optional: true });
const routerIsProvided = router !== null && !!envInjector.get(ActivatedRoute, null);
const lastSuccessfulNavigation = router?.lastSuccessfulNavigation();

if (!routerIsProvided) {
hasNavigationError = false;
} else if (lastSuccessfulNavigation?.finalUrl) {
} else if (router && lastSuccessfulNavigation?.finalUrl) {
hasNavigationError = false;

const requestPrefix =
Expand Down