You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(router): clarify how base href is used to construct targets (angular#38123)
The documentation is not clear on how the base href and APP_BASE_HREF are used. This commit
should help clarify more complicated use-cases beyond the most common one of just a '/'
PR Closeangular#38123
While the router uses the <ahref="https://developer.mozilla.org/en-US/docs/Web/API/History_API#Adding_and_modifying_history_entries"title="Browser history push-state">HTML5 pushState</a> style by default, you must configure that strategy with a `<base href>`.
545
554
546
555
The preferred way to configure the strategy is to add a <ahref="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base"title="base href"><base href> element</a> tag in the `<head>` of the `index.html`.
@@ -554,8 +563,16 @@ Some developers may not be able to add the `<base>` element, perhaps because the
554
563
555
564
Those developers may still use HTML5 URLs by taking the following two steps:
556
565
557
-
1. Provide the router with an appropriate [APP_BASE_HREF][] value.
558
-
1. Use root URLs for all web resources: CSS, images, scripts, and template HTML files.
566
+
1. Provide the router with an appropriate `APP_BASE_HREF` value.
567
+
1. Use root URLs (URLs with an `authority`) for all web resources: CSS, images, scripts, and template HTML files.
568
+
569
+
* The `<base href>``path` should end with a "/", as browsers ignore characters in the `path` that follow the right-most "/".
570
+
* If the `<base href>` includes a `query` part, the `query` is only used if the `path` of a link in the page is empty and has no `query`.
571
+
This means that a `query` in the `<base href>` is only included when using `HashLocationStrategy`.
572
+
* If a link in the page is a root URL (has an `authority`), the `<base href>` is not used. In this way, an `APP_BASE_HREF` with an authority will cause all links created by Angular to ignore the `<base href>` value.
573
+
* A fragment in the `<base href>` is _never_ persisted.
574
+
575
+
For more complete information on how `<base href>` is used to construct target URIs, see the [RFC](https://tools.ietf.org/html/rfc3986#section-5.2.2) section on transforming references.
0 commit comments