Location
A service that applications can use to interact with a browser's URL.
ngOnDestroy
void
void
path
string
Normalizes the URL path for this location.
boolean
True to include an anchor fragment in the path.
string
getState
unknown
Reports the current state of the location history.
unknown
isCurrentPathEqualTo
boolean
Normalizes the given path and compares to the current normalized path.
string
The given URL path.
string
Query parameters.
boolean
normalize
string
Normalizes a URL path by stripping any trailing slashes.
string
String representing a URL.
string
prepareExternalUrl
string
Normalizes an external URL path.
If the given URL doesn't begin with a leading slash ('/'
), adds one
before normalizing. Adds a hash if HashLocationStrategy
is
in use, or the APP_BASE_HREF
if the PathLocationStrategy
is in use.
string
String representing a URL.
string
go
void
Changes the browser's URL to a normalized version of a given URL, and pushes a new item onto the platform's history.
string
URL path to normalize.
string
Query parameters.
any
Location history state.
void
replaceState
void
Changes the browser's URL to a normalized version of the given URL, and replaces the top item on the platform's history stack.
string
URL path to normalize.
string
Query parameters.
any
Location history state.
void
forward
void
Navigates forward in the platform's history.
void
back
void
Navigates back in the platform's history.
void
historyGo
void
Navigate to a specific page from session history, identified by its relative position to the current page.
number
Position of the target page in the history relative to the current
page.
A negative value moves backwards, a positive value moves forwards, e.g. location.historyGo(2)
moves forward two pages and location.historyGo(-2)
moves back two pages. When we try to go
beyond what's stored in the history session, we stay in the current page. Same behaviour occurs
when relativePosition
equals 0.
void
onUrlChange
VoidFunction
Registers a URL change listener. Use to catch updates performed by the Angular framework that are not detectible through "popstate" or "hashchange" events.
(url: string, state: unknown) => void
The change handler function, which take a URL and a location history state.
VoidFunction
subscribe
SubscriptionLike
Subscribes to the platform's popState
events.
Note: Location.go()
does not trigger the popState
event in the browser. Use
Location.onUrlChange()
to subscribe to URL changes instead.
((exception: any) => void) | null | undefined
(() => void) | null | undefined
SubscriptionLike
normalizeQueryParams
(params: string) => string
Normalizes URL parameters by prepending with ?
if needed.
joinWithSlash
(start: string, end: string) => string
Joins two parts of a URL with a slash if needed.
stripTrailingSlash
(url: string) => string
Removes a trailing slash from a URL string if needed.
Looks for the first occurrence of either #
, ?
, or the end of the
line as /
characters and removes the trailing slash if one exists.