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(
228228 try {
229229 const renderingPromises : Promise < void > [ ] = [ ] ;
230230 const appShellRouteWithLeadingSlash = appShellRoute && addLeadingSlash ( appShellRoute ) ;
231- const baseHrefWithLeadingSlash = addLeadingSlash ( baseHref ) ;
231+ const baseHrefPathnameWithLeadingSlash = new URL ( baseHref , 'http://localhost' ) . pathname ;
232232
233233 for ( const { route, redirectTo } of serializableRouteTreeNode ) {
234234 // 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 ) )
237239 : route ;
238240
239241 const outPath = posix . join ( removeLeadingSlash ( routeWithoutBaseHref ) , 'index.html' ) ;
Original file line number Diff line number Diff line change @@ -615,13 +615,10 @@ export async function getRoutesFromAngularRouterConfig(
615615
616616 const errors : string [ ] = [ ] ;
617617
618- let baseHref =
618+ const rawBaseHref =
619619 injector . get ( APP_BASE_HREF , null , { optional : true } ) ??
620620 injector . get ( PlatformLocation ) . getBaseHrefFromDOM ( ) ;
621-
622- if ( baseHref . startsWith ( './' ) ) {
623- baseHref = baseHref . slice ( 2 ) ;
624- }
621+ const { pathname : baseHref } = new URL ( rawBaseHref , 'http://localhost' ) ;
625622
626623 const compiler = injector . get ( Compiler ) ;
627624 const serverRoutesConfig = injector . get ( SERVER_ROUTES_CONFIG , null , { optional : true } ) ;
Original file line number Diff line number Diff line change @@ -576,6 +576,25 @@ describe('extractRoutesAndCreateRouteTree', () => {
576576 ] ) ;
577577 } ) ;
578578
579+ it ( 'handles a baseHref starting with a protocol' , async ( ) => {
580+ setAngularAppTestingManifest (
581+ [ { path : 'home' , component : DummyComponent } ] ,
582+ [ { path : '**' , renderMode : RenderMode . Server } ] ,
583+ /** baseHref*/ 'http://foo.com/example/' ,
584+ ) ;
585+
586+ const { routeTree, errors } = await extractRoutesAndCreateRouteTree ( {
587+ url,
588+ invokeGetPrerenderParams : true ,
589+ includePrerenderFallbackRoutes : true ,
590+ } ) ;
591+
592+ expect ( errors ) . toHaveSize ( 0 ) ;
593+ expect ( routeTree . toObject ( ) ) . toEqual ( [
594+ { route : '/example/home' , renderMode : RenderMode . Server } ,
595+ ] ) ;
596+ } ) ;
597+
579598 it ( 'should not bootstrap the root component' , async ( ) => {
580599 @Component ( {
581600 standalone : true ,
You can’t perform that action at this time.
0 commit comments