mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 07:14:44 +00:00
fix($location): compare against actual instead of current URL
This commit is contained in:
parent
4bd7bedf48
commit
a348e90aa1
2 changed files with 67 additions and 5 deletions
|
|
@ -128,7 +128,7 @@ function LocationHtml5Url(appBase, basePrefix) {
|
||||||
} else {
|
} else {
|
||||||
return appBase + prevAppUrl;
|
return appBase + prevAppUrl;
|
||||||
}
|
}
|
||||||
} else if ( (appUrl = beginsWith(appBaseNoFile, url)) ) {
|
} else if ( (appUrl = beginsWith(appBaseNoFile, url)) !== undefined ) {
|
||||||
return appBaseNoFile + appUrl;
|
return appBaseNoFile + appUrl;
|
||||||
} else if (appBaseNoFile == url + '/') {
|
} else if (appBaseNoFile == url + '/') {
|
||||||
return appBaseNoFile;
|
return appBaseNoFile;
|
||||||
|
|
@ -524,12 +524,12 @@ function $LocationProvider(){
|
||||||
if (elm[0] === $rootElement[0] || !(elm = elm.parent())[0]) return;
|
if (elm[0] === $rootElement[0] || !(elm = elm.parent())[0]) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var absHref = elm.prop('href'),
|
var absHref = elm.prop('href');
|
||||||
rewrittenUrl = $location.$$rewrite(absHref);
|
var rewrittenUrl = $location.$$rewrite(absHref);
|
||||||
|
|
||||||
if (absHref && !elm.attr('target') && rewrittenUrl) {
|
if (absHref && !elm.attr('target') && rewrittenUrl) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (rewrittenUrl != initialUrl) {
|
if (rewrittenUrl != $browser.url()) {
|
||||||
// update location manually
|
// update location manually
|
||||||
$location.$$parse(rewrittenUrl);
|
$location.$$parse(rewrittenUrl);
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
|
|
|
||||||
|
|
@ -826,7 +826,15 @@ describe('$location', function() {
|
||||||
initLocation(),
|
initLocation(),
|
||||||
function($browser) {
|
function($browser) {
|
||||||
browserTrigger(link, 'click');
|
browserTrigger(link, 'click');
|
||||||
expectNoRewrite($browser, 'http://host.com/base/');
|
expectRewriteTo($browser, 'http://host.com/base/');
|
||||||
|
|
||||||
|
jqLite(link).attr('href', 'http://host.com/base/foo');
|
||||||
|
browserTrigger(link, 'click');
|
||||||
|
expectRewriteTo($browser, 'http://host.com/base/foo');
|
||||||
|
|
||||||
|
jqLite(link).attr('href', 'http://host.com/base/');
|
||||||
|
browserTrigger(link, 'click');
|
||||||
|
expectRewriteTo($browser, 'http://host.com/base/');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -1332,4 +1340,58 @@ describe('$location', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('LocationHtml5Url', function() {
|
||||||
|
var location, locationIndex;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
location = new LocationHtml5Url('http://server/pre/', 'http://server/pre/path');
|
||||||
|
locationIndex = new LocationHtml5Url('http://server/pre/index.html', 'http://server/pre/path');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should rewrite URL', function() {
|
||||||
|
expect(location.$$rewrite('http://other')).toEqual(undefined);
|
||||||
|
expect(location.$$rewrite('http://server/pre')).toEqual('http://server/pre/');
|
||||||
|
expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
|
||||||
|
expect(location.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/otherPath');
|
||||||
|
expect(locationIndex.$$rewrite('http://server/pre')).toEqual('http://server/pre/');
|
||||||
|
expect(locationIndex.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
|
||||||
|
expect(locationIndex.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/otherPath');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('LocationHashbangUrl', function() {
|
||||||
|
var location;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
location = new LocationHashbangUrl('http://server/pre/', 'http://server/pre/#/path');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should rewrite URL', function() {
|
||||||
|
expect(location.$$rewrite('http://other')).toEqual(undefined);
|
||||||
|
expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
|
||||||
|
expect(location.$$rewrite('http://server/pre/#otherPath')).toEqual('http://server/pre/#otherPath');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('LocationHashbangInHtml5Url', function() {
|
||||||
|
var location, locationIndex;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
location = new LocationHashbangInHtml5Url('http://server/pre/', '#!');
|
||||||
|
locationIndex = new LocationHashbangInHtml5Url('http://server/pre/index.html', '#!');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should rewrite URL', function() {
|
||||||
|
expect(location.$$rewrite('http://other')).toEqual(undefined);
|
||||||
|
expect(location.$$rewrite('http://server/pre')).toEqual('http://server/pre/');
|
||||||
|
expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
|
||||||
|
expect(location.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/#!otherPath');
|
||||||
|
expect(locationIndex.$$rewrite('http://server/pre')).toEqual('http://server/pre/');
|
||||||
|
expect(locationIndex.$$rewrite('http://server/pre/')).toEqual(undefined);
|
||||||
|
expect(locationIndex.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/index.html#!otherPath');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue