This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($location): always resolve relative links in html5mode to <base>
url
#8851
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> | ||
... | ||
</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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
<a href="#!/path/foo">foo</a>
would be broken by this (more specifically, the LocationHashbangInHtml5Url case would break this --- but it's the same code in both)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, this is a breaking change. But in html5 mode you should not use those kinds of urls, right? They are used in plain hashbang mode (without html5Mode turned on)