Location service that provides a drop-in replacement for the $location service provided in AngularJS.
API
class $locationShim {
constructor($injector: any, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy): $locationShim;
onChange(fn: (url: string, state: unknown, oldUrl: string, oldState: unknown) => void, err?: (e: Error) => void): void;
$$parse(url: string): void;
$$parseLinkUrl(url: string, relHref?: string | null | undefined): boolean;
absUrl(): string;
url(): string;
url(url: string): this;
protocol(): string;
host(): string;
port(): number | null;
path(): string;
path(path: string | number | null): this;
search(): { [key: string]: unknown; };
search(search: string | number | { [key: string]: unknown; }): this;
search(search: string | number | { [key: string]: unknown; }, paramValue: string | number | boolean | string[] | null | undefined): this;
hash(): string;
hash(hash: string | number | null): this;
replace(): this;
state(): unknown;
state(state: unknown): this;
}
constructor
$locationShimany
Location
PlatformLocation
LocationStrategy
$locationShim
onChange
voidRegisters 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).
(url: string, state: unknown, oldUrl: string, oldState: unknown) => voidThe callback function that is triggered for the listener when the URL changes.
(e: Error) => voidThe callback function that is triggered when an error occurs.
void
$$parse
voidParses the provided URL, and sets the current URL to the parsed result.
stringThe URL string.
void
$$parseLinkUrl
booleanParses the provided URL and its relative URL.
stringThe full URL string.
string | null | undefinedA URL string relative to the full URL string.
boolean
absUrl
stringRetrieves 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=xoxo let absUrl = $location.absUrl(); // => "http://example.com/#/some/path?foo=bar&baz=xoxo"
string
url
2 overloadsRetrieves 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=xoxo let url = $location.url(); // => "/some/path?foo=bar&baz=xoxo"
string
string
this
protocol
stringRetrieves the protocol of the current URL.
// given URL http://example.com/#/some/path?foo=bar&baz=xoxo let protocol = $location.protocol(); // => "http"
string
host
stringRetrieves 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=xoxo let host = $location.host(); // => "example.com" // given URL http://user:[email protected]:8080/#/some/path?foo=bar&baz=xoxo host = $location.host(); // => "example.com" host = location.host; // => "example.com:8080"
string
port
number | nullRetrieves the port of the current URL.
// given URL http://example.com/#/some/path?foo=bar&baz=xoxo let port = $location.port(); // => 80
number | null
path
2 overloadsRetrieves 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=xoxo let path = $location.path(); // => "/some/path"
string
string | number | null
this
search
3 overloadsRetrieves a map of the search parameters of the current URL, or changes a search part and returns a reference to its own instance.
// given URL http://example.com/#/some/path?foo=bar&baz=xoxo
let searchObject = $location.search();
// => {foo: 'bar', baz: 'xoxo'}
// set foo to 'yipee'
$location.search('foo', 'yipee');
// $location.search() => {foo: 'yipee', baz: 'xoxo'}
{ [key: string]: unknown; }
string | number | { [key: string]: unknown; }
this
string | number | { [key: string]: unknown; }
string | number | boolean | string[] | null | undefined
this
hash
2 overloadsRetrieves 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#hashValue let hash = $location.hash(); // => "hashValue"
string
string | number | null
this
replace
thisChanges to $location during the current $digest will replace the current history record, instead of adding a new one.
this
state
2 overloadsRetrieves 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.
unknown
unknown
this