@ngdoc overview @name Developer Guide: Angular Services: Using $location @description # What does it do? The `$location` service parses the URL in the browser address bar (based on the [window.location](https://developer.mozilla.org/en/window.location)) and makes the URL available to your application. Changes to the URL in the address bar are reflected into $location service and changes to $location are reflected into the browser address bar. **The $location service:** - Exposes the current URL in the browser address bar, so you can - Watch and observe the URL. - Change the URL. - Maintains synchronization between itself and the browser's URL when the user - Changes the address in the browser's address bar. - Clicks the back or forward button in the browser (or clicks a History link). - Clicks on a link in the page. - Represents the URL object as a set of methods (protocol, host, port, path, search, hash). ## Comparing $location to window.location
| window.location | $location service | |
|---|---|---|
| purpose | allow read/write access to the current browser location | same | 
| API | exposes "raw" object with properties that can be directly modified | exposes jQuery-style getters and setters | 
| integration with angular application life-cycle | none | knows about all internal life-cycle phases, integrates with $watch, ... | 
| seamless integration with HTML5 API | no | yes (with a fallback for legacy browsers) | 
| aware of docroot/context from which the application is loaded | no - window.location.path returns "/docroot/actual/path" | yes - $location.path() returns "/actual/path" | 
 
| Hashbang mode | HTML5 mode | |
|---|---|---|
| configuration | the default | { html5Mode: true } | 
| URL format | hashbang URLs in all browsers | regular URLs in modern browser, hashbang URLs in old browser | 
| <a href=""> link rewriting | no | yes | 
| requires server-side configuration | no | yes | 
| Navigation inside the app | Change to | 
|---|---|
| $location.href = value $location.hash = value $location.update(value) $location.updateHash(value) | $location.path(path).search(search) | 
| $location.hashPath = path | $location.path(path) | 
| $location.hashSearch = search | $location.search(search) | 
| Navigation outside the app | Use lower level API | 
| $location.href = value $location.update(value) | $window.location.href = value | 
| $location[protocol | host | port | path | search] | $window.location[protocol | host | port | path | search] | 
| Read access | Change to | 
| $location.hashPath | $location.path() | 
| $location.hashSearch | $location.search() | 
| $location.href $location.protocol $location.host $location.port $location.hash | $location.absUrl() $location.protocol() $location.host() $location.port() $location.path() + $location.search() | 
| $location.path $location.search | $window.location.path $window.location.search |