Skip to content

Commit dfe68c7

Browse files
atscottclydin
authored andcommitted
fix(@angular/ssr): SSR should work without @angular/router
This fixes SSR to ensure serialization is not broken when router is not provided.
1 parent 1d26eb5 commit dfe68c7

File tree

1 file changed

+5
-2
lines changed
  • packages/angular/ssr/src/utils

1 file changed

+5
-2
lines changed

packages/angular/ssr/src/utils/ng.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
platformServer,
2121
ɵrenderInternal as renderInternal,
2222
} from '@angular/platform-server';
23-
import { Router } from '@angular/router';
23+
import { ActivatedRoute, Router } from '@angular/router';
2424
import { Console } from '../console';
2525
import { joinUrlParts, stripIndexHtmlFromURL } from './url';
2626

@@ -98,10 +98,13 @@ export async function renderAngular(
9898

9999
// TODO(alanagius): Find a way to avoid rendering here especially for redirects as any output will be discarded.
100100
const envInjector = applicationRef.injector;
101+
const routerIsProvided = !!envInjector.get(ActivatedRoute, null);
101102
const router = envInjector.get(Router);
102103
const lastSuccessfulNavigation = router.lastSuccessfulNavigation;
103104

104-
if (lastSuccessfulNavigation?.finalUrl) {
105+
if (!routerIsProvided) {
106+
hasNavigationError = false;
107+
} else if (lastSuccessfulNavigation?.finalUrl) {
105108
hasNavigationError = false;
106109

107110
const { finalUrl, initialUrl } = lastSuccessfulNavigation;

0 commit comments

Comments
 (0)