mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +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 {
|
||||
return appBase + prevAppUrl;
|
||||
}
|
||||
} else if ( (appUrl = beginsWith(appBaseNoFile, url)) ) {
|
||||
} else if ( (appUrl = beginsWith(appBaseNoFile, url)) !== undefined ) {
|
||||
return appBaseNoFile + appUrl;
|
||||
} else if (appBaseNoFile == url + '/') {
|
||||
return appBaseNoFile;
|
||||
|
|
@ -524,12 +524,12 @@ function $LocationProvider(){
|
|||
if (elm[0] === $rootElement[0] || !(elm = elm.parent())[0]) return;
|
||||
}
|
||||
|
||||
var absHref = elm.prop('href'),
|
||||
rewrittenUrl = $location.$$rewrite(absHref);
|
||||
var absHref = elm.prop('href');
|
||||
var rewrittenUrl = $location.$$rewrite(absHref);
|
||||
|
||||
if (absHref && !elm.attr('target') && rewrittenUrl) {
|
||||
event.preventDefault();
|
||||
if (rewrittenUrl != initialUrl) {
|
||||
if (rewrittenUrl != $browser.url()) {
|
||||
// update location manually
|
||||
$location.$$parse(rewrittenUrl);
|
||||
$rootScope.$apply();
|
||||
|
|
|
|||
|
|
@ -826,7 +826,15 @@ describe('$location', function() {
|
|||
initLocation(),
|
||||
function($browser) {
|
||||
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