This repository was 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
docs($location): clarify guide regarding link handling #8908
Closed
Closed
Changes from all commits
Commits
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 hidden or 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 |
---|---|---|
|
@@ -210,6 +210,10 @@ facilitate the browser URL change and history management. | |
## Hashbang mode (default mode) | ||
|
||
In this mode, `$location` uses Hashbang URLs in all browsers. | ||
Angular also does not intercept and rewrite links in this mode. I.e. links work | ||
as expected and also perform full page reloads when other parts of the url | ||
than the hash fragment was changed. | ||
|
||
|
||
### Example | ||
|
||
|
@@ -249,6 +253,10 @@ having to worry about whether the browser displaying your app supports the histo | |
- Opening a regular URL in a legacy browser -> redirects to a hashbang URL | ||
- Opening hashbang URL in a modern browser -> rewrites to a regular URL | ||
|
||
Note that in this mode, Angular intercepts all links and updates the url in a way | ||
that never performs a full page reload (see "Html link rewriting" below). | ||
|
||
|
||
### Example | ||
|
||
```js | ||
|
@@ -297,7 +305,7 @@ history API or not; the `$location` service makes this transparent to you. | |
|
||
### Html link rewriting | ||
|
||
When you use HTML5 history API mode, you will need different links in different browsers, but all you | ||
When you use HTML5 history API mode, you will not need different links in different browsers, but all you | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... you will not need special hashbang links. All you have to do ... |
||
have to do is specify regular URL links, such as: `<a href="/some?foo=bar">link</a>` | ||
|
||
When a user clicks on this link, | ||
|
@@ -313,17 +321,9 @@ reload to the original link. | |
Example: `<a href="/ext/link?a=b" target="_self">link</a>` | ||
- Absolute links that go to a different domain<br> | ||
Example: `<a href="http://angularjs.org/">link</a>` | ||
- Links starting with '/' that lead to a different base path when base is defined<br> | ||
- Links starting with '/' that lead to a different base path<br> | ||
Example: `<a href="/not-my-base/link">link</a>` | ||
|
||
When running Angular in the root of a domain, along side perhaps a normal application in the same | ||
directory, the "otherwise" route handler will try to handle all the URLs, including ones that map | ||
to static files. | ||
|
||
To prevent this, you can set your base href for the app to `<base href=".">` and then prefix links | ||
to URLs that should be handled with `.`. Now, links to locations, which are not to be routed by Angular, | ||
are not prefixed with `.` and will not be intercepted by the `otherwise` rule in your `$routeProvider`. | ||
|
||
|
||
### Relative links | ||
|
||
|
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.
I don't think this is the case if you don't provide an
otherwise()
clause to$routeProvider
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 independent of
$route
being loaded or not. If the url of the link matches the<base>
we always do aevent.preventDefault()
on the click event for links in$location
.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.
Oh right. Of course! In that case we should be saying: