From e4b8eebd7050f8542af29611d4a2e891f730497f Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Tue, 7 Apr 2020 23:31:11 +0200 Subject: [PATCH] adapt createHref instead of prependBasePath --- src/core/public/application/scoped_history.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/public/application/scoped_history.ts b/src/core/public/application/scoped_history.ts index 67e98ce8582529..6c145dfff842de 100644 --- a/src/core/public/application/scoped_history.ts +++ b/src/core/public/application/scoped_history.ts @@ -229,9 +229,17 @@ export class ScopedHistory prependBasePath: boolean = true ): Href => { this.verifyActive(); - return this.parentHistory.createHref( - prependBasePath ? this.prependBasePath(location) : location - ); + if (prependBasePath) { + location = this.prependBasePath(location); + if (location.pathname === undefined) { + // we always want to create an url relative to the basePath + // so if pathname is not present, we use the history's basePath as default + // we are doing that here because `prependBasePath` should not + // alter pathname for other method calls + location.pathname = this.basePath; + } + } + return this.parentHistory.createHref(location); }; private prependBasePath(path: Path): Path; @@ -252,7 +260,7 @@ export class ScopedHistory pathname: pathOrLocation.pathname !== undefined ? this.prependBasePathToString(pathOrLocation.pathname) - : this.basePath, + : undefined, }; } }