66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { PlatformLocation } from '@angular/common' ;
9+ import { LocationStrategy } from '@angular/common' ;
1010import {
1111 ApplicationRef ,
1212 type PlatformRef ,
@@ -21,9 +21,9 @@ import {
2121 platformServer ,
2222 ɵrenderInternal as renderInternal ,
2323} from '@angular/platform-server' ;
24- import { ActivatedRoute , Router } from '@angular/router' ;
24+ import { ActivatedRoute , Router , UrlSerializer } from '@angular/router' ;
2525import { Console } from '../console' ;
26- import { stripIndexHtmlFromURL , stripTrailingSlash } from './url' ;
26+ import { stripIndexHtmlFromURL } from './url' ;
2727
2828/**
2929 * Represents the bootstrap mechanism for an Angular application.
@@ -107,11 +107,14 @@ export async function renderAngular(
107107
108108 if ( ! routerIsProvided ) {
109109 hasNavigationError = false ;
110- } else if ( lastSuccessfulNavigation ) {
110+ } else if ( lastSuccessfulNavigation ?. finalUrl ) {
111111 hasNavigationError = false ;
112- const { pathname, search, hash } = envInjector . get ( PlatformLocation ) ;
113- const finalUrl = [ stripTrailingSlash ( pathname ) , search , hash ] . join ( '' ) ;
114- const finalUrlHref = decodeURIComponent ( new URL ( finalUrl , urlToRender . origin ) . href ) ;
112+
113+ const urlSerializer = envInjector . get ( UrlSerializer ) ;
114+ const finalUrlSerialized = urlSerializer . serialize ( lastSuccessfulNavigation . finalUrl ) ;
115+ const locationStrategy = envInjector . get ( LocationStrategy ) ;
116+ const finalUrl = locationStrategy . prepareExternalUrl ( finalUrlSerialized ) ;
117+ const finalUrlHref = new URL ( finalUrl , urlToRender . origin ) . href ;
115118 const urlToRenderHref = decodeURIComponent ( urlToRender . href ) ;
116119
117120 if ( urlToRenderHref !== finalUrlHref ) {
0 commit comments