• Overview
@angular/common/upgrade

$locationShim

Class

Location service that provides a drop-in replacement for the $location service provided in AngularJS.

  
    class $locationShim {
}

onChange

void

Registers listeners for URL changes. This API is used to catch updates performed by the AngularJS framework. These changes are a subset of the $locationChangeStart and $locationChangeSuccess events which fire when AngularJS updates its internally-referenced version of the browser URL.

It's possible for $locationChange events to happen, but for the browser URL (window.location) to remain unchanged. This onChange callback will fire only when AngularJS actually updates the browser URL (window.location).

@paramfn(url: string, state: unknown, oldUrl: string, oldState: unknown) => void

The callback function that is triggered for the listener when the URL changes.

@paramerr(e: Error) => void

The callback function that is triggered when an error occurs.

@returnsvoid

$$parse

void

Parses the provided URL, and sets the current URL to the parsed result.

@paramurlstring

The URL string.

@returnsvoid

$$parseLinkUrl

boolean

Parses the provided URL and its relative URL.

@paramurlstring

The full URL string.

@paramrelHrefstring | null | undefined

A URL string relative to the full URL string.

@returnsboolean

absUrl

string

Retrieves the full URL representation with all segments encoded according to rules specified in RFC 3986.

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

url

2 overloads

Retrieves the current URL, or sets a new URL. When setting a URL, changes the path, search, and hash, and returns a reference to its own instance.

          
// given URL http://example.com/#/some/path?foo=bar&baz=xoxolet url = $location.url();// => "/some/path?foo=bar&baz=xoxo"
@returnsstring
@paramurlstring
@returnsthis

protocol

string

Retrieves the protocol of the current URL.

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

host

string

Retrieves the protocol of the current URL.

In contrast to the non-AngularJS version location.host which returns hostname:port, this returns the hostname portion only.

          
// given URL http://example.com/#/some/path?foo=bar&baz=xoxolet host = $location.host();// => "example.com"// given URL http://user:password@example.com:8080/#/some/path?foo=bar&baz=xoxohost = $location.host();// => "example.com"host = location.host;// => "example.com:8080"
@returnsstring

port

number | null

Retrieves the port of the current URL.

          
// given URL http://example.com/#/some/path?foo=bar&baz=xoxolet port = $location.port();// => 80
@returnsnumber | null

path

2 overloads

Retrieves the path of the current URL, or changes the path and returns a reference to its own instance.

Paths should always begin with forward slash (/). This method adds the forward slash if it is missing.

          
// given URL http://example.com/#/some/path?foo=bar&baz=xoxolet path = $location.path();// => "/some/path"
@returnsstring
@parampathstring | number | null
@returnsthis

hash

2 overloads

Retrieves the current hash fragment, or changes the hash fragment and returns a reference to its own instance.

          
// given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValuelet hash = $location.hash();// => "hashValue"
@returnsstring
@paramhashstring | number | null
@returnsthis

replace

this

Changes to $location during the current $digest will replace the current history record, instead of adding a new one.

@returnsthis

state

2 overloads

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

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

@returnsunknown
@paramstateunknown
@returnsthis
Jump to details