PathLocationStrategy
来源:互联网 发布:python爬虫框架 知乎 编辑:程序博客网 时间:2024/06/04 18:43
功能:利用URL储存当前应用的本地数据。
概况:
class PathLocationsStrategy extends LocationsStrategy{ constructor(_platformLocation: PlatformLocation, href?: string)onPopState(fn: LocationChangeListener) : voidgetBaseHref() : stringprepareExternalUrl(internal: string) : stringpath(includeHash?: boolean) : stringpushState(state: any, title: string, url: string, queryParams: string)replaceState(state: any, title: string, url: string, queryParams: string)forward() : voidback() : void}
类描述:
PathLocationStrategy 就是LocationStrategy被用于配置Location的一种服务,用于表示浏览器URL路径中状态。
如果你正在使用PathLocationStrategy,你必须提供一个APP_BASE_HREF或者增加一个基础元素给到文档。当生成以及识别URL时,这个URL的前缀将会被预存。
我们举一个实例,如果你提供一个/my/app的APP_BASE_HREF并且调用了location.go(‘/foo’)。浏览器URL就会编程example.com/my/app/foo.
类似的,如果你添加
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';import {Component} from '@angular/core';@Component({ selector: 'path-location', providers: [Location, {provide: LocationStrategy, useClass: PathLocationStrategy}], template: ` <h1>PathLocationStrategy</h1> Current URL is: <code>{{location.path()}}</code><br> Normalize: <code>/foo/bar/</code> is: <code>{{location.normalize('foo/bar')}}</code><br> `})export class PathLocationComponent { location: Location; constructor(location: Location) { this.location = location; }}
注解:@Injectable();
构造函数:constructor(_platformLocation: PlatformLocation, href?: string)
0 0