Skip to content

Location does not support base href containing origin (only base hrefs with just the path are supported) #48175

@constantant

Description

@constantant

Which @angular/* package(s) are the source of the bug?

common, localize, router

Is this a regression?

No

Description

Routing gets broken if APP_BASE_HREF changed manually.

Regarding the docs, while deploying the bundles to CDN it needs to change the APP_BASE_HREF token to a URL where an app gonna be launched.

  provide: APP_BASE_HREF,
  useFactory: () => {
    const [, root, locale] = location.pathname.split('/');
    return `//${ location.host }/${ root }/${ locale }/`
  }

There is a simple implementation of it: https://github.com/constantant/cdn-i18n-routing-issue

Please provide a link to a minimal reproduction of the bug

https://konstantin.kharitonov.nl/cdn-i18n-routing-issue/en/

Please provide the exception or error you saw

core.mjs:9235 ERROR Error: Uncaught (in promise): Error: NG04002
Error: NG04002
    at j.noMatchError (router.mjs:3663:16)
    at router.mjs:3645:28
    at catchError.js:10:39
    at ne._error (OperatorSubscriber.js:23:21)
    at ne.error (Subscriber.js:40:18)
    at ne._error (Subscriber.js:64:30)
    at ne.error (Subscriber.js:40:18)
    at ne._error (Subscriber.js:64:30)
    at ne.error (Subscriber.js:40:18)
    at ne._error (Subscriber.js:64:30)
    at q (zone.js:1211:31)
    at q (zone.js:1165:17)
    at zone.js:1278:17
    at v.invokeTask (zone.js:406:31)
    at Object.onInvokeTask (core.mjs:26589:33)
    at v.invokeTask (zone.js:405:60)
    at M.runTask (zone.js:178:47)
    at _ (zone.js:585:35)
handleError @ core.mjs:9235
next @ core.mjs:27286
next @ Subscriber.js:91
_next @ Subscriber.js:60
next @ Subscriber.js:31
(anonymous) @ Subject.js:34
ne @ errorContext.js:19
next @ Subject.js:27
emit @ core.mjs:23077
(anonymous) @ core.mjs:26628
invoke @ zone.js:372
run @ zone.js:134
runOutsideAngular @ core.mjs:26501
onHandleError @ core.mjs:26628
handleError @ zone.js:376
runGuarded @ zone.js:147
i.microtaskDrainDone @ zone.js:1072
_ @ zone.js:592
Promise.then (async)
z @ zone.js:561
R @ zone.js:572
scheduleTask @ zone.js:396
onScheduleTask @ zone.js:283
scheduleTask @ zone.js:386
scheduleTask @ zone.js:221
scheduleMicroTask @ zone.js:241
ee @ zone.js:1265
q @ zone.js:1202
(anonymous) @ zone.js:1118
(anonymous) @ zone.js:1134
n @ jsonp chunk loading:77
(anonymous) @ 338.ac20b7bb511b4118.js:1
Show 18 more frames

Please provide the environment you discovered this bug in (run ng version)

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 15.0.0
Node: 16.13.1
Package Manager: npm 8.14.0
OS: win32 x64

Angular: 15.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.0
@angular-devkit/build-angular   15.0.0
@angular-devkit/core            15.0.0
@angular-devkit/schematics      15.0.0
@schematics/angular             15.0.0
rxjs                            7.5.7
typescript                      4.8.4

Anything else?

Notice that the minimal reproduction is building as a multilingual app with ng build --localize

The whole pipeline is available here: https://github.com/constantant/cdn-i18n-routing-issue/blob/master/.github/workflows/main.yml

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: commonIssues related to APIs in the @angular/common packageworkaround2: non-obvious

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions