angular/packages/common/src
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
..
directives fix(common): allow null/undefined to be passed to ngClass input (#39280) (#46906) 2022-08-01 12:55:13 -07:00
i18n docs: fix spelling (#46713) 2022-07-08 20:54:52 +00:00
location refactor(common): Align PathLocationStrategy constructor with default factory (#46929) 2022-08-01 14:21:14 -07:00
pipes feat(common): make the CommonModule pipes standalone (#46401) 2022-06-23 13:51:43 -07:00
common.ts feat(common): add injection token for default date pipe timezone (#43611) 2021-10-06 13:53:09 -07:00
common_module.ts feat(common): make the CommonModule directives standalone (#46469) 2022-06-28 12:55:25 -07:00
cookie.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
dom_adapter.ts refactor: replace deprecated HTMLDocument with Document (#45282) 2022-03-08 13:12:14 -08:00
dom_tokens.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
errors.ts fix(core): Update ngfor error code to be negative (#46555) 2022-06-28 12:59:07 -07:00
platform_id.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
private_export.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
version.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
viewport_scroller.ts refactor(common): unused return value from attemptFocus (#44457) 2022-01-21 13:11:30 -08:00
xhr.ts fix(platform-browser): configure XhrFactory to use BrowserXhr (#41313) 2021-03-29 15:14:16 -07:00