PathLocationStrategy class

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 appBaseHref to a string representing the URL prefix that should be preserved when generating and recognizing URLs.

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

Example

import 'package:angular/angular.dart' show bootstrap, Component, provide;
import 'package:angular_router/angular_router.dart'
  show
    appBaseHref,
    Location,
    ROUTER_DIRECTIVES,
    ROUTER_PROVIDERS,
    RouteConfig;

@Component({directives: [ROUTER_DIRECTIVES]})
@RouteConfig([
 {...},
])
class AppCmp {
  constructor(location: Location) {
    location.go('/foo');
  }
}

bootstrap(AppCmp, [
  ROUTER_PROVIDERS, // includes binding to PathLocationStrategy
  provide(appBaseHref, {useValue: '/my/app'})
]);
Inheritance
Annotations
  • @Injectable()

Constructors

PathLocationStrategy(PlatformLocation _platformLocation, [ @Optional() @Inject(appBaseHref) String href ])

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 url, String queryParams) → void
override
replaceState(dynamic state, String title, String url, 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