Skip to content

Commit

Permalink
fix($location): return '/' for root path in hashbang mode
Browse files Browse the repository at this point in the history
Before this change, on the root of the application, $location.path() would return
the empty string. Following this change, it will always return a root of '/'.

Closes angular#5650
  • Loading branch information
caitp committed Jan 9, 2014
1 parent 28fc80b commit 09bf754
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ function LocationHashbangUrl(appBase, hashPrefix) {

this.$$compose();

if (!this.$$path) {
this.$$path = '/';
}

/*
* In Windows, on an anchor node on documents loaded from
* the filesystem, the browser will return a pathname
Expand Down
10 changes: 10 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,16 @@ describe('$location', function() {
expect(location.url()).toBe('/not-starting-with-slash');
expect(location.absUrl()).toBe('http://server/pre/index.html#/not-starting-with-slash');
});


it("should return / for path for the application root path", function() {
location = new LocationHashbangUrl('http://server/pre/index.html', '#');
location.$$parse('http://server/pre/index.html');
expect(location.path()).toBe('/');

location.$$parse('http://server/pre/');
expect(location.path()).toBe('/');
});
});


Expand Down

0 comments on commit 09bf754

Please sign in to comment.