2016-04-29 00:50:03 +00:00
|
|
|
import {OpaqueToken} from '@angular/core';
|
2016-01-21 17:58:28 +00:00
|
|
|
import {UrlChangeListener} from './platform_location';
|
2015-11-17 18:47:59 +00:00
|
|
|
|
2015-09-22 00:31:31 +00:00
|
|
|
/**
|
|
|
|
|
* `LocationStrategy` is responsible for representing and reading route state
|
2015-11-25 22:06:06 +00:00
|
|
|
* from the browser's URL. Angular provides two strategies:
|
2016-02-01 02:34:20 +00:00
|
|
|
* {@link HashLocationStrategy} and {@link PathLocationStrategy} (default).
|
2015-09-22 00:31:31 +00:00
|
|
|
*
|
|
|
|
|
* This is used under the hood of the {@link Location} service.
|
|
|
|
|
*
|
|
|
|
|
* Applications should use the {@link Router} or {@link Location} services to
|
|
|
|
|
* interact with application route state.
|
|
|
|
|
*
|
|
|
|
|
* For instance, {@link HashLocationStrategy} produces URLs like
|
|
|
|
|
* `http://example.com#/foo`, and {@link PathLocationStrategy} produces
|
|
|
|
|
* `http://example.com/foo` as an equivalent URL.
|
|
|
|
|
*
|
|
|
|
|
* See these two classes for more.
|
|
|
|
|
*/
|
2015-09-25 21:48:17 +00:00
|
|
|
export abstract class LocationStrategy {
|
|
|
|
|
abstract path(): string;
|
2015-10-26 13:57:41 +00:00
|
|
|
abstract prepareExternalUrl(internal: string): string;
|
2015-09-23 07:10:26 +00:00
|
|
|
abstract pushState(state: any, title: string, url: string, queryParams: string): void;
|
2015-12-08 00:05:57 +00:00
|
|
|
abstract replaceState(state: any, title: string, url: string, queryParams: string): void;
|
2015-09-25 21:48:17 +00:00
|
|
|
abstract forward(): void;
|
|
|
|
|
abstract back(): void;
|
2016-01-21 17:58:28 +00:00
|
|
|
abstract onPopState(fn: UrlChangeListener): void;
|
2015-09-25 21:48:17 +00:00
|
|
|
abstract getBaseHref(): string;
|
2015-06-22 19:14:19 +00:00
|
|
|
}
|
2015-09-23 07:10:26 +00:00
|
|
|
|
2015-11-17 18:47:59 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The `APP_BASE_HREF` token represents the base href to be used with the
|
|
|
|
|
* {@link PathLocationStrategy}.
|
|
|
|
|
*
|
|
|
|
|
* If you're using {@link PathLocationStrategy}, you must provide a provider to a string
|
|
|
|
|
* representing the URL prefix that should be preserved when generating and recognizing
|
|
|
|
|
* URLs.
|
|
|
|
|
*
|
|
|
|
|
* ### Example
|
|
|
|
|
*
|
|
|
|
|
* ```
|
2016-04-29 00:50:03 +00:00
|
|
|
* import {Component} from '@angular/core';
|
|
|
|
|
* import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig} from '@angular/router';
|
|
|
|
|
* import {APP_BASE_HREF} from '@angular/common';
|
2015-11-17 18:47:59 +00:00
|
|
|
*
|
|
|
|
|
* @Component({directives: [ROUTER_DIRECTIVES]})
|
|
|
|
|
* @RouteConfig([
|
|
|
|
|
* {...},
|
|
|
|
|
* ])
|
|
|
|
|
* class AppCmp {
|
|
|
|
|
* // ...
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* bootstrap(AppCmp, [
|
|
|
|
|
* ROUTER_PROVIDERS,
|
|
|
|
|
* provide(APP_BASE_HREF, {useValue: '/my/app'})
|
|
|
|
|
* ]);
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
2016-04-26 04:47:33 +00:00
|
|
|
export const APP_BASE_HREF: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken('appBaseHref');
|