# Class Location

##### Index

### Constructors

constructor

### Properties

$$state
absUrl
appBase
appBaseNoFile
basePrefix
hashPrefix
html5

### Methods

getHash
getPath
getSearch
getState
getUrl
parse
parseLinkUrl
setHash
setPath
setSearch
setState
setUrl

## Constructors

### constructor

- new Location(
  appBase: string,
  appBaseNoFile: string,
  html5?: boolean,
  prefix?: string,
  ): Location

  #### Parameters

  - appBase: string

    application base URL

  - appBaseNoFile: string

    application base URL stripped of any filename

  - `Optional` html5: boolean = true

    Defaults to true

  - `Optional` prefix: string

    URL path prefix for html5 mode or hash prefix for hashbang mode

  #### Returns Location

## Properties

### $$state

$$state: any

### 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) with all segments encoded according to rules specified in RFC 3986.

### appBase

appBase: string

### appBaseNoFile

appBaseNoFile: string

### basePrefix

basePrefix: string

### hashPrefix

hashPrefix: string

### html5

html5: boolean

## Methods

### getHash

- getHash(): string

  Returns the hash fragment when called without any parameters.

  #### Returns string

  hash

### getPath

- getPath(): string

  Return path of current URL

  #### Returns string

### getSearch

- getSearch(): any

  Returns the search part (as object) of current URL

  #### Returns any

  Search object or Location object

### getState

- getState(): any

  Return the history state object

  #### Returns any

### getUrl

- getUrl(): string

  Return URL (e.g. `/path?a=b#hash`) when called without any parameter.

  #### Returns string

  url

### parse

- parse(url: string): void

  Parse given HTML5 (regular) URL string into properties

  #### Parameters

  - url: string

    HTML5 URL

  #### Returns void

### parseLinkUrl

- parseLinkUrl(url: string, relHref: string): boolean

  #### Parameters

  - url: string
  - relHref: string

  #### Returns boolean

### setHash

- setHash(hash: string | number): Location

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

  #### Parameters

  - hash: string | number

    New hash fragment

  #### Returns Location

  hash

### setPath

- setPath(path: string | number): Location

  Change path parameter and return `$location`.

  #### Parameters

  - path: string | number

    New path

  #### Returns Location

### setSearch

- setSearch(
  search: any,
  paramValue: string | number | boolean | string[],
  ...args: any,
  ): any

  Sets the search part (as object) of current URL

  #### 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.

  - ...args: any

  #### Returns any

  Search object or Location object

### setState

- setState(state: any): Location

  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

  #### Returns Location

### setUrl

- setUrl(url: string): Location

  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 Location

  url