UNPKG

angular2

Version:

Angular 2 - a web framework for modern web apps

110 lines (109 loc) 3.53 kB
import { LocationStrategy } from './location_strategy'; import { OpaqueToken } from 'angular2/angular2'; /** * 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 * * ``` * import {Component} from 'angular2/angular2'; * import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig} from 'angular2/router'; * * @Component({directives: [ROUTER_DIRECTIVES]}) * @RouteConfig([ * {...}, * ]) * class AppCmp { * // ... * } * * bootstrap(AppCmp, [ * ROUTER_PROVIDERS, * PathLocationStrategy, * provide(APP_BASE_HREF, {useValue: '/my/app'}) * ]); * ``` */ export declare const APP_BASE_HREF: OpaqueToken; /** * `Location` is a service that applications can use to interact with a browser's URL. * Depending on which {@link LocationStrategy} is used, `Location` will either persist * to the URL's path or the URL's hash segment. * * Note: it's better to use {@link Router#navigate} 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 normalized * - `my/app/user/123` **is not** normalized * - `/my/app/user/123/` **is not** normalized * * ### Example * * ``` * import {Component} from 'angular2/angular2'; * import { * ROUTER_DIRECTIVES, * ROUTER_PROVIDERS, * RouteConfig, * Location * } from 'angular2/router'; * * @Component({directives: [ROUTER_DIRECTIVES]}) * @RouteConfig([ * {...}, * ]) * class AppCmp { * constructor(location: Location) { * location.go('/foo'); * } * } * * bootstrap(AppCmp, [ROUTER_PROVIDERS]); * ``` */ export declare class Location { platformStrategy: LocationStrategy; constructor(platformStrategy: LocationStrategy, href?: string); /** * Returns the normalized URL path. */ path(): string; /** * Given a string representing a URL, returns the normalized URL path without leading or * trailing slashes */ normalize(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. */ prepareExternalUrl(url: string): string; /** * Changes the browsers URL to the normalized version of the given URL, and pushes a * new item onto the platform's history. */ go(path: string, query?: string): void; /** * Navigates forward in the platform's history. */ forward(): void; /** * Navigates back in the platform's history. */ back(): void; /** * Subscribe to the platform's `popState` events. */ subscribe(onNext: (value: any) => void, onThrow?: (exception: any) => void, onReturn?: () => void): Object; }