`Unhandled Navigation Error` error shown when I use --base-href with cdn address instead of --deploy-url
See original GitHub issueπ Bug report
Command (mark with an x
)
- new
- build
- serve
- test
- e2e
- generate
- add
- update
- lint
- extract-i18n
- run
- config
- help
- version
- doc
Is this a regression?
YesDescription
As this PR(angular/angular-cli/pull/21537) said, we can set `--base-href` to the CDN address because `--deploy-url` will be deprecated next version. So I follow this to change the command of building application.Here is the cmd:
node --max_old_space_size=4096 ./node_modules/.bin/ng build --prod --base-href=//mycdn.com/xxx
When I try to use http-server
to start it, the error Unhandled Navigation Error
shown. Iβm not sure if I missed something or set wrong configurations in my application.
π¬ Minimal Reproduction
// app.module.ts
...
providers: [
{ provide: APP_BASE_HREF, useValue: '/' }
...
],
...
// app-routing.module.ts, `loadChildren` in routes
...
@NgModule({
imports: [
RouterModule.forRoot(routes, {
useHash: true,
preloadingStrategy: PreloadAllModules,
relativeLinkResolution: 'legacy'
})
],
exports: [RouterModule]
})
...
// build cmd
node --max_old_space_size=4096 ./node_modules/.bin/ng build --prod --base-href=//mycdn.com/xxx
// start server
http-server --proxy xxxx
π₯ Exception or Error
Unhandled Navigation Error: main-es2015.5fc8829f03fd1c12af29.js:formatted:15045
......
π Your Environment
Angular CLI: 12.2.3
Node: 14.17.5
Package Manager: npm 6.14.14
OS: darwin x64
Angular: 12.2.3
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, localize, platform-browser, platform-browser-dynamic
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1201.1
@angular-devkit/build-angular 12.2.2
@angular-devkit/core 12.1.1
@angular-devkit/schematics 12.2.3
@schematics/angular 12.2.3
rxjs 6.6.7
typescript 4.3.5
Anything else relevant?
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (9 by maintainers)
Top Results From Across the Web
Unhandled Navigation Error error shown when I use --base ...
As this PR(angular/angular-cli/pull/21537) said, we can set `--base-href` to the CDN address because `--deploy-url` will be deprecated nextΒ ...
Read more >Unhandled Navigation Error: When BaseHref is different from ...
I have one web app (Angular 8.0) hosted on one domain. For normal users it is working fine. But when it comes to...
Read more >angular 13 base href Code Example - Code Grepper
Answers related to βangular 13 base hrefβ. get current url angular Β· angular redirect to external url Β· angular decode url Β· link...
Read more >Angular --deploy-url and --base-href - The art of simplicity
If you deploy your Angular app to a subfolder, the '--base-href' is important to generate the correct routes. This parameter will update the...
Read more >single-spa-angular
APP_BASE_HREF should have the same value that the used url for mount the Angular app defined in the single-spa root application. But doing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for your update, I think building with cdn and using docker to deploy(pull all cdn files including js&assets) is not
uncommon edge case
. I will try to usePathLocationStrategy
andAPP_BASE_HREF
to check if this can sovle my problem likea
link not work, thanks again π@atscott, users might encounter this more in v13 due to the deprecation of the
deployUrl
option in the CLI. More context https://github.com/angular/angular-cli/pull/21537None-the-less this issue occurs only when combining 2 legacy/old techniques together which Iβd say is not as common. Considering this and that there is amply time until
deployUrl
is completely removed from the CLI, I am inclined in saying that we should not handle it and users should move towards a modern setup. Until then use the deprecateddeployUrl
option should be used.The mentioned old techniques are;