# Class Location

#### Abstract

#### Hierarchy (view full)

- Location
  - LocationHtml5Url
  - LocationHashbangUrl

- Defined in core/location/location.js:40

#####
Index

### Constructors

constructor

### Properties

$$absUrl
$$hash
$$host
$$html5
$$path
$$port
$$protocol
$$replace
$$search
$$state
$$url
$$urlUpdatedByLocation
appBase
appBaseNoFile

### Methods

$$compose
$$normalizeUrl
$$parse
$$parseLinkUrl
absUrl
hash
host
path
port
protocol
replace
search
state
url

##
Constructors

### constructor

- new Location(appBase, appBaseNoFile): Location

- #### Parameters

  - appBase: string

    application base URL

  - appBaseNoFile: string

    application base URL stripped of any filename

  #### Returns Location

  - Defined in core/location/location.js:45

##
Properties

### $$absUrl

$$absUrl: string

An absolute URL is the full URL, including protocol (http/https ), the optional subdomain (e.g. www ), domain (example.com), and path (which includes the directory and slug).

- Defined in core/location/location.js:56
- Defined in core/location/location.js:288

### $$hash

$$hash: string

The hash string, minus the hash symbol

- Defined in core/location/location.js:92
- Defined in core/location/location.js:226

### $$host

$$host: string

- Defined in core/location/location.js:74

### $$html5

$$html5: boolean

If html5 mode is enabled

- Defined in core/location/location.js:62

### $$path

$$path: string

The pathname, beginning with "/"

- Defined in core/location/location.js:86
- Defined in core/location/location.js:199

### $$port

$$port: number

The port, without ":"

- Defined in core/location/location.js:80

### $$protocol

$$protocol: HttpProtocol

- Defined in core/location/location.js:71

### $$replace

$$replace: boolean

Has any change been replacing?

- Defined in core/location/location.js:68
- Defined in core/location/location.js:236

### $$search

$$search: any

- Defined in core/location/location.js:254
- Defined in core/location/location.js:262

### $$state

$$state: any

- Defined in core/location/location.js:331

### $$url

$$url: string

- Defined in core/location/location.js:287

### $$urlUpdatedByLocation

$$urlUpdatedByLocation: boolean

Helper property for scope watch changes

- Defined in core/location/location.js:98
- Defined in core/location/location.js:289
- Defined in core/location/location.js:332

### appBase

appBase: string

- Defined in core/location/location.js:47

### appBaseNoFile

appBaseNoFile: string

- Defined in core/location/location.js:50

##
Methods

### $$compose

- $$compose(): void

- Compose url and update `url` and `absUrl` property

  #### Returns void

  - Defined in core/location/location.js:286

### $$normalizeUrl

- $$normalizeUrl(_url): string

- #### Parameters

  - _url: string

  #### Returns string

  - Defined in core/location/location.js:296

### $$parse

- $$parse(_url): void

- #### Parameters

  - _url: any

  #### Returns void

  - Defined in core/location/location.js:346

### $$parseLinkUrl

- $$parseLinkUrl(_url, _url2): boolean

- #### Parameters

  - _url: string
  - _url2: string

  #### Returns boolean

  - Defined in core/location/location.js:342

### absUrl

- absUrl(): string

- Return full URL representation with all segments encoded according to rules specified in RFC 3986.

  #### Returns string

  full URL

  - Defined in core/location/location.js:107

### hash

- hash(hash): string | Location

- This method is getter / setter.

  Returns the hash fragment when called without any parameters.

  Changes the hash fragment when called with a parameter and returns `$location`.

      // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
      let hash = $location.hash();
      // => "hashValue"

  #### Parameters

  - hash: string | number

    New hash fragment

  #### Returns string | Location

  hash

  - Defined in core/location/location.js:221

### host

- host(): string

- This method is getter only.

  Return host of current URL.

  Note: compared to the non-AngularJS version `location.host` which returns `hostname:port`, this returns the `hostname` portion only.

  #### Returns string

  host of current URL.

  - Defined in core/location/location.js:152

### path

- path(path): any

- This method is getter / setter.

  Return path of current URL when called without any parameter.

  Change path when called with parameter and return `$location`.

  Note: Path should always begin with forward slash (/), this method will add the forward slash if it is missing.

      // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
      let path = $location.path();
      // => "/some/path"

  #### Parameters

  - path: string | number

    New path

  #### Returns any

  path if called with no parameters, or `$location` if called with a parameter

  - Defined in core/location/location.js:194

### port

- port(): number

- This method is getter only.

  Return port of current URL.

      // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
      let port = $location.port();
      // => 80

  #### Returns number

  port

  - Defined in core/location/location.js:170

### protocol

- protocol(): HttpProtocol

- Return protocol of current URL.

  #### Returns HttpProtocol

  protocol of current URL

  - Defined in core/location/location.js:138

### replace

- replace(): Location

- If called, all changes to $location during the current `$digest` will replace the current history record, instead of adding a new one.

  #### Returns Location

  - Defined in core/location/location.js:235

### search

- search(search, paramValue, ...args): any

- Returns or sets the search part (as object) of current URL when called without any parameter

  #### Parameters

  - search: any

    New search params - string or hash object.

  - paramValue:
    | string
    | number
    | boolean
    | string[]

    If search is a string or number, then paramValue will override only a single search property.

  - `Rest`...args: any

  #### Returns any

  Search object or Location object

  - Defined in core/location/location.js:247

### state

- state(state, ...args): any

- This method is getter / setter.

  Return the history state object when called without any parameter.

  Change the history state object when called with one parameter and return `$location`. The state object is later passed to `pushState` or `replaceState`. See https://developer.mozilla.org/en-US/docs/Web/API/History/pushState#state|History.state

  NOTE: This method is supported only in HTML5 mode and only in browsers supporting the HTML5 History API (i.e. methods `pushState` and `replaceState`). If you need to support older browsers (like IE9 or Android < 4.0), don't use this method.

  #### Parameters

  - state: any

    State object for pushState or replaceState

  - `Rest`...args: any

  #### Returns any

  state

  - Defined in core/location/location.js:316

### url

- url(url): string | Location

- This method is getter / setter.

  Return URL (e.g. `/path?a=b#hash`) when called without any parameter. Change path, search and hash, when called with parameter and return `$location`.

  #### Parameters

  - url: string

    New URL without base prefix (e.g. `/path?a=b#hash`)

  #### Returns string | Location

  url

  - Defined in core/location/location.js:120