-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Commit
…` url BREAKING CHANGE (since 1.2.0 and 1.3.0-beta.1): Angular now requires a `<base>` tag when html5 mode of `$location` is enabled. Reasoning: Using html5 mode without a `<base href="...">` tag makes relative links for images, links, ... relative to the current url if the browser supports the history API. However, if the browser does not support the history API Angular falls back to using the `#`, and then all those relative links would be broken. The `<base>` tag is also needed when a deep url is loaded from the server, e.g. `http://server/some/page/url`. In that case, Angular needs to decide which part of the url is the base of the application, and which part is path inside of the application. To summarize: Now all relative links are always relative to the `<base>` tag. Exception (also a breaking change): Link tags whose `href` attribute starts with a `#` will only change the hash of the url, but nothing else (e.g. `<a href="#someAnchor">`). This is to make it easy to scroll to anchors inside a document. Related to #6162 Closes #8492 BREAKING CHANGE (since 1.2.17 and 1.3.0-beta.10): In html5 mode without a `<base>` tag on older browser that don't support the history API relative paths were adding up. E.g. clicking on `<a href="page1">` and then on `<a href="page2">` would produce `$location.path()==='/page1/page2'. The code that introduced this behavior was removed and Angular now also requires a `<base>` tag to be present when using html5 mode. Closes #8172, #8233
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@ngdoc error | ||
@name $location:nobase | ||
@fullName $location in HTML5 mode requires a <base> tag to be present! | ||
@description | ||
|
||
If you configure {@link ng.$location `$location`} to use | ||
{@ng.provider.$locationProvider `html5Mode`} (`history.pushState`), you need to specify the base URL for the application with a [`<base href="">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base) tag. | ||
|
||
The base URL is then used to resolve all relative URLs throughout the application regardless of the | ||
entry point into the app. | ||
|
||
If you are deploying your app into the root context (e.g. `https://myapp.com/`), set the base URL to `/`: | ||
|
||
```html | ||
<head> | ||
<base href="/"> | ||
... | ||
</head> | ||
``` | ||
|
||
If you are deploying your app into a sub-context (e.g. `https://myapp.com/subapp/`), set the base URL to the | ||
URL of the subcontext: | ||
|
||
```html | ||
<head> | ||
<base href="/myapp"> | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
... | ||
</head> | ||
``` | ||
|
||
Before Angular 1.3 we didn't have this hard requirement and it was easy to write apps that worked | ||
when deployed in the root context but were broken when moved to a sub-context because in the | ||
sub-context all absolute urls would resolve to the root context of the app. To prevent this, | ||
use relative URLs throughout your app: | ||
|
||
```html | ||
<!-- wrong: --> | ||
<a href="/userProfile">User Profile</a> | ||
|
||
|
||
<!-- correct: --> | ||
<a href="userProfile">User Profile</a> | ||
|
||
``` | ||
|
||
Additionally, if you want to support [browsers that don't have the `history.pushState` | ||
API](http://caniuse.com/#feat=history), the fallback mechanism provided by `$location` | ||
won't work well without specifying the base url of the application. | ||
|
||
In order to make it easier to migrate from hashbang mode to html5 mode, we require that the base | ||
URL is always specified when `$location`'s `html5mode` is enabled. |
4 comments
on commit 2294880
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it add to 1.2.x version as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we will add this to 1.2.x as well. Just waiting for a little but to get all the regressions first...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any update on when this will be added to 1.2.x?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Excited to see this come to 1.2.x.
Shouldn't this rather be
href="/subapp"
?