File tree Expand file tree Collapse file tree 3 files changed +26
-8
lines changed
build/src/utils/server-rendering Expand file tree Collapse file tree 3 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -228,12 +228,14 @@ async function renderPages(
228
228
try {
229
229
const renderingPromises : Promise < void > [ ] = [ ] ;
230
230
const appShellRouteWithLeadingSlash = appShellRoute && addLeadingSlash ( appShellRoute ) ;
231
- const baseHrefWithLeadingSlash = addLeadingSlash ( baseHref ) ;
231
+ const baseHrefPathnameWithLeadingSlash = new URL ( baseHref , 'http://localhost' ) . pathname ;
232
232
233
233
for ( const { route, redirectTo } of serializableRouteTreeNode ) {
234
234
// Remove the base href from the file output path.
235
- const routeWithoutBaseHref = addTrailingSlash ( route ) . startsWith ( baseHrefWithLeadingSlash )
236
- ? addLeadingSlash ( route . slice ( baseHrefWithLeadingSlash . length ) )
235
+ const routeWithoutBaseHref = addTrailingSlash ( route ) . startsWith (
236
+ baseHrefPathnameWithLeadingSlash ,
237
+ )
238
+ ? addLeadingSlash ( route . slice ( baseHrefPathnameWithLeadingSlash . length ) )
237
239
: route ;
238
240
239
241
const outPath = posix . join ( removeLeadingSlash ( routeWithoutBaseHref ) , 'index.html' ) ;
Original file line number Diff line number Diff line change @@ -569,13 +569,10 @@ export async function getRoutesFromAngularRouterConfig(
569
569
570
570
const errors : string [ ] = [ ] ;
571
571
572
- let baseHref =
572
+ const rawBaseHref =
573
573
injector . get ( APP_BASE_HREF , null , { optional : true } ) ??
574
574
injector . get ( PlatformLocation ) . getBaseHrefFromDOM ( ) ;
575
-
576
- if ( baseHref . startsWith ( './' ) ) {
577
- baseHref = baseHref . slice ( 2 ) ;
578
- }
575
+ const { pathname : baseHref } = new URL ( rawBaseHref , 'http://localhost' ) ;
579
576
580
577
const compiler = injector . get ( Compiler ) ;
581
578
const serverRoutesConfig = injector . get ( SERVER_ROUTES_CONFIG , null , { optional : true } ) ;
Original file line number Diff line number Diff line change @@ -510,6 +510,25 @@ describe('extractRoutesAndCreateRouteTree', () => {
510
510
] ) ;
511
511
} ) ;
512
512
513
+ it ( 'handles a baseHref starting with a protocol' , async ( ) => {
514
+ setAngularAppTestingManifest (
515
+ [ { path : 'home' , component : DummyComponent } ] ,
516
+ [ { path : '**' , renderMode : RenderMode . Server } ] ,
517
+ /** baseHref*/ 'http://foo.com/example/' ,
518
+ ) ;
519
+
520
+ const { routeTree, errors } = await extractRoutesAndCreateRouteTree ( {
521
+ url,
522
+ invokeGetPrerenderParams : true ,
523
+ includePrerenderFallbackRoutes : true ,
524
+ } ) ;
525
+
526
+ expect ( errors ) . toHaveSize ( 0 ) ;
527
+ expect ( routeTree . toObject ( ) ) . toEqual ( [
528
+ { route : '/example/home' , renderMode : RenderMode . Server } ,
529
+ ] ) ;
530
+ } ) ;
531
+
513
532
it ( 'should not bootstrap the root component' , async ( ) => {
514
533
@Component ( {
515
534
standalone : true ,
You can’t perform that action at this time.
0 commit comments