@ngdoc overview @name Using $location @sortOrder 500 @description # Using the `$location` service The `$location` service parses the URL in the browser address bar (based on [`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 the `$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 AngularJS application life-cycle | none | knows about all internal life-cycle phases, integrates with {@link ng.$rootScope.Scope#$watch $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.pathname 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 |