export class Location
export class Location
exported from angular2/router defined in angular2/src/router/location.ts (line 3)
Location
is a service that applications can use to interact with a browser's URL.
Depending on which LocationStrategy
is used, Location
will either persist
to the URL's path or the URL's hash segment.
Note: it's better to use Router
service to trigger route changes. Use
Location
only if you need to interact with or create normalized URLs outside of
routing.
Location
is responsible for normalizing the URL against the application's base href.
A normalized URL is absolute from the URL host, includes the application's base href, and has no
trailing slash:
/my/app/user/123
is normalizedmy/app/user/123
is not normalized/my/app/user/123/
is not normalized
Example
Annotations
@Injectable()
@Injectable()
Constructor
constructor(platformStrategy: LocationStrategy)
constructor(platformStrategy: LocationStrategy)
Not Yet Documented
Members
platformStrategy : LocationStrategy
platformStrategy : LocationStrategy
Not Yet Documented
path() : string
path() : string
Returns the normalized URL path.
normalize(url: string) : string
normalize(url: string) : string
Given a string representing a URL, returns the normalized URL path without leading or trailing slashes
prepareExternalUrl(url: string) : string
prepareExternalUrl(url: string) : string
Given a string representing a URL, returns the platform-specific external URL path.
If the given URL doesn't begin with a leading slash ('/'
), this method adds one
before normalizing. This method will also add a hash if HashLocationStrategy
is
used, or the APP_BASE_HREF
if the PathLocationStrategy
is in use.
go(path: string, query?: string) : void
go(path: string, query?: string) : void
Changes the browsers URL to the normalized version of the given URL, and pushes a new item onto the platform's history.
replaceState(path: string, query?: string) : void
replaceState(path: string, query?: string) : void
Changes the browsers URL to the normalized version of the given URL, and replaces the top item on the platform's history stack.
forward() : void
forward() : void
Navigates forward in the platform's history.
back() : void
back() : void
Navigates back in the platform's history.
subscribe(onNext: (value: any) => void, onThrow?: (exception: any) => void, onReturn?: () => void) : Object
subscribe(onNext: (value: any) => void, onThrow?: (exception: any) => void, onReturn?: () => void) : Object
Subscribe to the platform's popState
events.