HashLocationStrategy class

HashLocationStrategy is a LocationStrategy used to configure the PlatformLocation service to represent its state in the hash fragment of the browser's URL.

For instance, if you call location.go('/foo'), the browser's URL will become example.com#/foo.

Example

import {Component, provide} from 'angular2/core';
import {
  Location,
  LocationStrategy,
  HashLocationStrategy
} 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,
  provide(LocationStrategy, {useClass: HashLocationStrategy})
]);
Inheritance
Annotations
  • @Injectable()

Constructors

HashLocationStrategy(PlatformLocation _platformLocation, [ @Optional() @Inject(appBaseHref) String baseHref ])

Properties

hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

back() → void
override
forward() → void
override
getBaseHref() → String
override
hash() → String
override
onPopState(EventListener fn) → void
override
path() → String
override
prepareExternalUrl(String internal) → String
override
pushState(dynamic state, String title, String path, String queryParams) → void
override
replaceState(dynamic state, String title, String path, String queryParams) → void
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited