W3cubDocs

/Angular

LocationStrategy

Enables the Location service to read route state from the browser's URL. Angular provides two strategies: HashLocationStrategy and PathLocationStrategy.

API

abstract class LocationStrategy {
  abstract path(includeHash?: boolean | undefined): string;
  abstract prepareExternalUrl(internal: string): string;
  abstract getState(): unknown;
  abstract pushState(state: any, title: string, url: string, queryParams: string): void;
  abstract replaceState(state: any, title: string, url: string, queryParams: string): void;
  abstract forward(): void;
  abstract back(): void;
  optional historyGo(relativePosition: number): void;
  abstract onPopState(fn: LocationChangeListener): void;
  abstract getBaseHref(): string;
}

path

string
@paramincludeHashboolean | undefined
@returnsstring

prepareExternalUrl

string
@paraminternalstring
@returnsstring

getState

unknown
@returnsunknown

pushState

void
@paramstateany
@paramtitlestring
@paramurlstring
@paramqueryParamsstring
@returnsvoid

replaceState

void
@paramstateany
@paramtitlestring
@paramurlstring
@paramqueryParamsstring
@returnsvoid

forward

void
@returnsvoid

back

void
@returnsvoid

historyGo

void
@paramrelativePositionnumber
@returnsvoid

onPopState

void
@returnsvoid

getBaseHref

string
@returnsstring

Description

Enables the Location service to read route state from the browser's URL. Angular provides two strategies: HashLocationStrategy and PathLocationStrategy.

Applications should use the Router or Location services to interact with application route state.

For instance, HashLocationStrategy produces URLs like http://example.com/#/foo, and PathLocationStrategy produces http://example.com/foo as an equivalent URL.

See these two classes for more.

Super-powered by Google ©2010–2025.
Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0.
https://angular.dev/api/common/LocationStrategy