mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
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 |
||
|---|---|---|
| .. | ||
| directives | ||
| i18n | ||
| location | ||
| pipes | ||
| common.ts | ||
| common_module.ts | ||
| cookie.ts | ||
| dom_adapter.ts | ||
| dom_tokens.ts | ||
| errors.ts | ||
| platform_id.ts | ||
| private_export.ts | ||
| version.ts | ||
| viewport_scroller.ts | ||
| xhr.ts | ||