Deliver web apps with confidence 🚀
Find a file
Andrew Scott 1fe759d9a4 refactor(common): Align PathLocationStrategy constructor with default factory (#46929)
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
2022-08-01 14:21:14 -07:00
.circleci fixup! ci: use actual main branch for components repo unit test job (#46743) 2022-07-08 16:19:56 +00:00
.devcontainer docs: fixed typos (#47008) 2022-08-01 11:15:54 -07:00
.github build: update cross-repo angular dependencies to 6d9c069 (#46905) 2022-08-01 09:38:34 -07:00
.husky build: remove unnecessary husky gitignore file (#42870) 2021-07-19 17:31:55 -07:00
.ng-dev ci: update .ng-dev pull request config to reflect recent API changes (#46642) 2022-07-01 10:20:51 -07:00
.vscode docs: initial upload of styles used by doc linter (#46897) 2022-08-01 09:29:06 -07:00
.yarn build: update to yarn v1.22.17 (#44150) 2021-11-15 11:19:05 -08:00
aio docs: fix link to live example (#47011) 2022-08-01 14:20:36 -07:00
devtools build: simplify sass consumption of Angular CDK/Material in devtools (#46642) 2022-07-01 10:20:51 -07:00
docs build: remove scripts and documentation about individual usage of RBE (#46515) 2022-06-27 10:50:08 -07:00
goldens fix(common): allow null/undefined to be passed to ngClass input (#39280) (#46906) 2022-08-01 12:55:13 -07:00
integration feat(platform-browser): add isEmpty method to the TransferState class (#46915) 2022-07-22 09:17:47 +00:00
modules build: disable jasminewd2 types for sourcemap playground test (#46888) 2022-07-19 09:40:54 -07:00
packages refactor(common): Align PathLocationStrategy constructor with default factory (#46929) 2022-08-01 14:21:14 -07:00
scripts build: update dependency firebase-tools to v11 (#46779) 2022-07-11 21:42:08 +00:00
third_party test: remove unused intl polyfill from tests and third_party vendoring (#46512) 2022-06-27 09:03:48 -07:00
tools build: replace size-tracking test with rule from shared dev-infra (#46802) 2022-07-12 19:06:30 +00:00
.bazelignore refactor(devtools): bring the angular devtools directory into the root bazel workspace 2022-01-26 16:35:31 -05:00
.bazelrc build: convert release package build scripts to typescript (#46456) 2022-06-22 14:35:31 -07:00
.bazelversion build: update to bazel v5 for new runfiles API used in dev-infra (#45407) 2022-03-21 16:55:36 -07:00
.clang-format feat(tooling): Add a .clang-format for automated JavaScript formatting. 2015-04-02 08:44:34 -07:00
.editorconfig build: use https link to editorconfig.org in .editorconfig (#27664) 2018-12-18 09:30:09 -08:00
.gitattributes build: cleanup .gitattributes file and remove outdated CRLF attribute (#46513) 2022-06-28 13:38:27 -07:00
.gitignore ci: fix stamping for builds performed in CI (#45147) 2022-02-25 19:14:05 +00:00
.gitmessage build: clean up references to old master branch (#45856) 2022-05-04 16:23:33 -07:00
.mailmap build: add a Git .mailmap with my new name (#19550) 2017-10-09 14:35:30 -07:00
.npmrc build: rely on engines to prevent using npm for dependency install (#41477) 2021-04-07 12:05:01 -07:00
.nvmrc build: update repository to node@16 locally (#44211) 2021-11-24 18:55:33 +00:00
.prettierrc ci: use prettier to format yml files (#42136) 2021-05-19 11:20:20 -07:00
.pullapprove.yml build: update doc approvers (#46939) 2022-07-22 15:39:34 +00:00
.yarnrc build: update to yarn v1.22.17 (#44150) 2021-11-15 11:19:05 -08:00
browser-providers.conf.js ci: enable Android 12 for tests on CI (#45926) 2022-05-09 11:26:10 -07:00
BUILD.bazel test: avoid test fixture affecting zone in all web tests (#46511) 2022-06-27 15:46:41 -07:00
CHANGELOG.md docs: release notes for the v14.1.0 release 2022-07-20 10:47:42 -07:00
CHANGELOG_ARCHIVE.md docs: move old changelog entries to a separate file (#45638) 2022-04-14 15:01:21 -07:00
CODE_OF_CONDUCT.md build: update CODE_OF_CONDUCT.md to match the content of angular/.github 2022-07-22 18:29:44 +00:00
CONTRIBUTING.md build: account for rename of angular/code-of-conduct default branch (#46640) 2022-06-30 12:44:05 -07:00
gulpfile.js build: remove the unused source-map-test (#46518) 2022-06-27 15:42:43 -07:00
karma-js.conf.js build: move jasmine seed generation logic to karma config (#46798) 2022-07-12 15:54:51 +00:00
LICENSE build: bump license year (#44590) 2022-01-04 12:05:25 -08:00
package.json build: update bazel setup to v5.5.3 (#47000) 2022-08-01 12:55:44 -07:00
README.md docs(core): add circleci insights metrics widget (#46496) 2022-06-24 17:04:06 -07:00
renovate.json ci: switch to explicit commit message body for renovate (#46676) 2022-07-06 13:46:48 -07:00
SECURITY.md build: update SECURITY.md to match the content of angular/.github 2022-07-22 18:34:00 +00:00
tsconfig-tslint.json refactor(devtools): run ng-dev format on angular devtools files 2022-01-26 16:35:30 -05:00
tslint.json refactor(devtools): bring the angular devtools directory into the root bazel workspace 2022-01-26 16:35:31 -05:00
WORKSPACE build: update io_bazel_rules_sass digest to 030f696 (#46947) 2022-08-01 09:40:03 -07:00
yarn.lock build: update bazel setup to v5.5.3 (#47000) 2022-08-01 12:55:44 -07:00
yarn.lock.readme.md build: clean up references to old master branch (#45856) 2022-05-04 16:23:33 -07:00

Angular - The modern web developer's platform.

angular-logo
Angular is a development platform for building mobile and desktop web applications
using Typescript/JavaScript and other languages.

www.angular.io

Contributing Guidelines · Submit an Issue · Blog

CI status   Angular on npm   Discord conversation

InsightsSnapshot


Documentation

Get started with Angular, learn the fundamentals and explore advanced topics on our documentation website.

Advanced

Development Setup

Prerequisites

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

Get started in 5 minutes.

Ecosystem

angular ecosystem logos

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 badge

Love Angular? Give our repo a star ⬆️.