From 6d7e7fdea6c3d6551ff40c150aa42e1375d2cb5f Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 11 Apr 2012 23:46:23 -0700 Subject: fix($location): properly rewrite urls in html5 mode with base url set previously we were doing all kinds of checks to see if we should rewrite the url or not and we were missing many scenarios. not any more. with this change, we rewrite the url unless: - the href is not set - link has target attribute - the absolute url of the link doesn't match the absolute prefix for all urls in our app This also means that ng-ext-link attribute which we previously used to distinguish external links from app links is not necessary any more. apps can just set target=_self to prevent rewriting. BREAKING CHANGE: ng-ext-link directive was removed because it's unnecessary apps that relied on ng-ext-link should simply replace it with target=_self --- .../guide/dev_guide.services.$location.ngdoc | 35 ++++++++++++---------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'docs/content/guide/dev_guide.services.$location.ngdoc') diff --git a/docs/content/guide/dev_guide.services.$location.ngdoc b/docs/content/guide/dev_guide.services.$location.ngdoc index c99d26b0..f7ca5dbe 100644 --- a/docs/content/guide/dev_guide.services.$location.ngdoc +++ b/docs/content/guide/dev_guide.services.$location.ngdoc @@ -305,7 +305,7 @@ history API or not; the `$location` service makes this transparent to you. ### Html link rewriting When you use the history API mode, you will need different links in different browser, but all you -have to do is specify regular URL links, such as: `<a href="/some?foo=bar">link</a>` +have to do is specify regular URL links, such as: `link` When a user clicks on this link, @@ -316,12 +316,13 @@ When a user clicks on this link, In cases like the following, links are not rewritten; instead, the browser will perform a full page reload to the original link. -- Links with an `ngExtLink` directive
- Example: `link` -- Links that contain `target="_blank"`
- Example: `link` -- Absolute links that go to a different domain
+- Links that contain `target` element
+ Example: `link` +- Absolute links that go to a different domain
Example: `link` +- Links starting with '/' that lead to a different base path when base is defined
+ Example: `link` + ### Server side @@ -341,11 +342,13 @@ Applications Crawlable}. ### Relative links -Be sure to check all relative links, images, scripts etc. You must use an absolute path because the -path is going to be rewritten. You can use `` tag as well. +Be sure to check all relative links, images, scripts etc. You must either specify the url base in +the head of your main html file (``) or you must use absolute urls +(starting with `/`) everywhere because relative urls will be resolved to absolute urls using the +initial absolute url of the document, which is often different from the root of the application. Running Angular apps with the History API enabled from document root is strongly encouraged as it -takes care of all relative link issues. **Otherwise you have to specify <base href="" /> !** +takes care of all relative link issues. ### Sending links among different browsers @@ -379,9 +382,9 @@ In this examples we use `` $location.path() = {{$location.path()}}
$location.search() = {{$location.search()}}
$location.hash() = {{$location.hash()}}
- /base/first?a=b | - sec/ond?flag#hash | - external + /base/first?a=b | + sec/ond?flag#hash | + external
@@ -393,9 +396,9 @@ In this examples we use `` $location.path() = {{$location.path()}}
$location.search() = {{$location.search()}}
$location.hash() = {{$location.hash()}}
- /base/first?a=b | - sec/ond?flag#hash | - external + /base/first?a=b | + sec/ond?flag#hash | + external
@@ -445,7 +448,7 @@ In this examples we use `` $compileProvider.directive('ngAddressBar', function() { return function(scope, elm, attrs) { var browser = browsers[attrs.browser], - input = angular.element('').val(browser.url()), + input = angular.element('').val(browser.url()), delay; input.bind('keypress keyup keydown', function() { -- cgit v1.2.3