When using the Angular Router, one of `APP_BASE_HREF` or a `<base>` in the header must be provided. When _not_ using the `RouterModule`, injecting the `LocationStrategy` will result in the `PathLocationStrategy` being provided with a default value used in place of `APP_BASE_HREF` that is `document?.location?.origin ?? ''`. It can be quite surprising and annoying that once you add `RouterModule` to the application, suddenly the `APP_BASE_HREF` must be specifically provide something new when it could use a sensible default instead. The current behavior (before this commit) is as follows: * When `RouterModule` is not provided (or the dev doesn't specifically provide `PathLocationStrategy`): use `DOCUMENT.location?.origin ?? ''`. Note that the base href in the dom and `APP_BASE_HREF` are not used. * When `RouterModule` _is_ provided: 1. APP_BASE_HREF if defined 2. Get base href from DOM 3. throw if neither of the two above are defined This commit updates this behavior to be aligned regardless of `RouterModule` usage. The order (by default) is now: 1. Developer provided `APP_BASE_HREF` 2. base href from the DOM 3. `location.origin` 4. If none of the above exist, use `''` This is slightly different than the behavior before. However, I believe it is more appropriate. For the case without `RouterModule`, it would likely be surprising that `APP_BASE_HREF` and the base href from the DOM are ignored by default. For the case with `RouterModule`, we now have a more sensible fallback/default when neither `APP_BASE_HREF` nor `<base>` are defined (instead of just throwing an error). PR Close #46929 |
||
|---|---|---|
| .circleci | ||
| .devcontainer | ||
| .github | ||
| .husky | ||
| .ng-dev | ||
| .vscode | ||
| .yarn | ||
| aio | ||
| devtools | ||
| docs | ||
| goldens | ||
| integration | ||
| modules | ||
| packages | ||
| scripts | ||
| third_party | ||
| tools | ||
| .bazelignore | ||
| .bazelrc | ||
| .bazelversion | ||
| .clang-format | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| .gitmessage | ||
| .mailmap | ||
| .npmrc | ||
| .nvmrc | ||
| .prettierrc | ||
| .pullapprove.yml | ||
| .yarnrc | ||
| browser-providers.conf.js | ||
| BUILD.bazel | ||
| CHANGELOG.md | ||
| CHANGELOG_ARCHIVE.md | ||
| CODE_OF_CONDUCT.md | ||
| CONTRIBUTING.md | ||
| gulpfile.js | ||
| karma-js.conf.js | ||
| LICENSE | ||
| package.json | ||
| README.md | ||
| renovate.json | ||
| SECURITY.md | ||
| tsconfig-tslint.json | ||
| tslint.json | ||
| WORKSPACE | ||
| yarn.lock | ||
| yarn.lock.readme.md | ||
Angular - The modern web developer's platform.
Angular is a development platform for building mobile and desktop web applications
using Typescript/JavaScript and other languages.
Contributing Guidelines
·
Submit an Issue
·
Blog
Documentation
Get started with Angular, learn the fundamentals and explore advanced topics on our documentation website.
Advanced
Development Setup
Prerequisites
- Install Node.js which includes Node Package Manager
Setting Up a Project
Install the Angular CLI globally:
npm install -g @angular/cli
Create workspace:
ng new [PROJECT NAME]
Run the application:
cd [PROJECT NAME]
ng serve
Angular is cross-platform, fast, scalable, has incredible tooling, and is loved by millions.
Quickstart
Ecosystem
Changelog
Learn about the latest improvements.
Upgrading
Check out our upgrade guide to find out the best way to upgrade your project.
Contributing
Contributing Guidelines
Read through our contributing guidelines to learn about our submission process, coding rules and more.
Want to Help?
Want to report a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues labeled as help wanted or good first issue.
Code of Conduct
Help us keep Angular open and inclusive. Please read and follow our Code of Conduct.
Community
Join the conversation and help the community.
Love Angular? Give our repo a star ⭐ ⬆️.