aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/location.js
diff options
context:
space:
mode:
authorMisko Hevery2012-06-11 21:24:23 -0700
committerIgor Minar2012-06-12 00:27:25 -0700
commit74fa65ecb7c4e2df966a179952b35700912e065f (patch)
treec949e6859c60c86bb4d215fec6a6a1390cbdaa2b /src/ng/location.js
parentee6014a3aa90232ed263fe9c9e0860c777b37a30 (diff)
downloadangular.js-74fa65ecb7c4e2df966a179952b35700912e065f.tar.bz2
fix($location): correctly parse link urls in hashbang mode
This is a fix for a regression that was introduced by 92a2e180 Closes #1037
Diffstat (limited to 'src/ng/location.js')
-rw-r--r--src/ng/location.js21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/ng/location.js b/src/ng/location.js
index 00f21559..7576015c 100644
--- a/src/ng/location.js
+++ b/src/ng/location.js
@@ -476,12 +476,14 @@ function $LocationProvider(){
this.$get = ['$rootScope', '$browser', '$sniffer', '$rootElement',
function( $rootScope, $browser, $sniffer, $rootElement) {
var $location,
- basePath = $browser.baseHref() || '/',
- pathPrefix = pathPrefixFromBase(basePath),
+ basePath,
+ pathPrefix,
initUrl = $browser.url(),
absUrlPrefix;
if (html5Mode) {
+ basePath = $browser.baseHref() || '/';
+ pathPrefix = pathPrefixFromBase(basePath);
if ($sniffer.history) {
$location = new LocationUrl(
convertToHtml5Url(initUrl, basePath, hashPrefix),
@@ -491,14 +493,14 @@ function $LocationProvider(){
convertToHashbangUrl(initUrl, basePath, hashPrefix),
hashPrefix);
}
+ // link rewriting
+ absUrlPrefix = composeProtocolHostPort(
+ $location.protocol(), $location.host(), $location.port()) + pathPrefix;
} else {
$location = new LocationHashbangUrl(initUrl, hashPrefix);
+ absUrlPrefix = $location.absUrl().split('#')[0];
}
- // link rewriting
- absUrlPrefix = composeProtocolHostPort(
- $location.protocol(), $location.host(), $location.port()) + pathPrefix;
-
$rootElement.bind('click', function(event) {
// TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
// currently we open nice url link and redirect then
@@ -512,7 +514,8 @@ function $LocationProvider(){
elm = elm.parent();
}
- var absHref = elm.prop('href');
+ var absHref = elm.prop('href'),
+ href;
if (!absHref ||
elm.attr('target') ||
@@ -521,7 +524,9 @@ function $LocationProvider(){
}
// update location with href without the prefix
- $location.url(absHref.substr(absUrlPrefix.length));
+ href = absHref.substr(absUrlPrefix.length);
+ if (href.charAt(0) == '#') href = href.substr(1);
+ $location.url(href);
$rootScope.$apply();
event.preventDefault();
// hack to work around FF6 bug 684208 when scenario runner clicks on links