PathLocationStrategy is a LocationStrategy used to configure the Location service to represent its state in the path of the browser's URL.

PathLocationStrategy is the default binding for LocationStrategy provided in ROUTER_PROVIDERS.

If you're using PathLocationStrategy, you must provide a provider for APP_BASE_HREF to a string representing the URL prefix that should be preserved when generating and recognizing URLs.

For instance, if you provide an APP_BASE_HREF of '/my/app' and call location.go('/foo'), the browser's URL will become example.com/my/app/foo.

Example

import {Component, provide} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {
  Location,
  APP_BASE_HREF
} from 'angular2/platform/common';
import {
  ROUTER_DIRECTIVES,
  ROUTER_PROVIDERS,
  RouteConfig
} from 'angular2/router';
 
@Component({directives: [ROUTER_DIRECTIVES]})
@RouteConfig([
 {...},
])
class AppCmp {
  constructor(location: Location) {
    location.go('/foo');
  }
}
 
bootstrap(AppCmp, [
  ROUTER_PROVIDERS, // includes binding to PathLocationStrategy
  provide(APP_BASE_HREF, {useValue: '/my/app'})
]);
Inheritance
Annotations

Constructors

PathLocationStrategy(PlatformLocation _platformLocation, [ @ @ String href ])

Properties

hashCode → int

Get a hash code for this object.

read-only, inherited
runtimeType → Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) → bool

The equality operator.

inherited

Methods

back() → void

forward() → void

getBaseHref() → String

hash() → String

noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
onPopState(EventListener fn) → void

path() → String

prepareExternalUrl(String internal) → String

pushState(state, String title, String url, String queryParams) → void

replaceState(state, String title, String url, String queryParams) → void

toString() → String

Returns a string representation of this object.

inherited