本文整理匯總了TypeScript中@angular/common.LocationStrategy類的典型用法代碼示例。如果您正苦於以下問題:TypeScript LocationStrategy類的具體用法?TypeScript LocationStrategy怎麽用?TypeScript LocationStrategy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了LocationStrategy類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor(public platformStrategy: LocationStrategy) {
super(1);
platformStrategy.onPopState(event => this._update('pop'));
const browserBaseHref = this.platformStrategy.getBaseHref();
this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
this._update('push');
}
示例2: it
it('should navigate back', fakeAsync(() => {
const {fixture, rootRenderer} = initTest(TestComponent, `<View><router-outlet></router-outlet></View>`);
const location: LocationStrategy = getTestBed().get(LocationStrategy);
const router: Router = getTestBed().get(Router);
router.initialNavigation();
tick();
fixture.detectChanges();
rootRenderer.executeCommands();
expect(mock.commandLogs.toString()).toEqual(
'CREATE+2+test-cmp+{},CREATE+3+native-view+{},CREATE+4+router-outlet+{},ATTACH+1+2+0,ATTACH+2+3+0,ATTACH+3+4+0,' +
'CREATE+5+cmp-a+{},CREATE+6+native-text+{},CREATE+7+native-rawtext+{"text":"a"},ATTACH+6+7+0,ATTACH+5+6+0,ATTACH+3+5+1');
mock.clearLogs();
router.navigateByUrl('/b')
.then((_: any) => {
tick();
fixture.detectChanges();
rootRenderer.executeCommands();
expect(mock.commandLogs.toString()).toEqual(
'CREATE+8+cmp-b+{},CREATE+9+native-text+{},CREATE+10+native-rawtext+{"text":"b"},DETACH+3+1,ATTACH+3+8+1,ATTACH+9+10+0,ATTACH+8+9+0');
mock.clearLogs();
})
.then((_: any) => {
location.back();
tick();
fixture.detectChanges();
rootRenderer.executeCommands();
expect(mock.commandLogs.toString()).toEqual(
'CREATE+11+cmp-a+{},CREATE+12+native-text+{},CREATE+13+native-rawtext+{"text":"a"},DETACH+3+1,ATTACH+3+11+1,ATTACH+12+13+0,ATTACH+11+12+0');
});
}));
示例3: constructor
constructor(public platformStrategy: LocationStrategy) {
super({ path: _path(platformStrategy), type: 'push' });
platformStrategy.onPopState(event => this._update('pop'));
this._baseHref = _getBaseHref(platformStrategy);
}
示例4: constructor
// I initialize the retro-location service. This provides an API that is
// reminiscent of the AngularJS 1.x $location service.
constructor( locationStrategy: LocationStrategy ) {
this.locationStrategy = locationStrategy;
this.popStateEvents = new Subject();
// When the underlying location implementation emits a PopStateEvent, we
// want to communicate that out to any clients that may be subscribed to the
// RetroLocation events.
this.locationStrategy.onPopState(
( event: PopStateEvent | HashChangeEvent ) : void => {
// Since RetroLocation will emit this event when the location is
// changed programmatically, we want to limit it to a single event-type,
// popstate, in order to make things a bit more predictable.
if ( event.type === "popstate" ) {
this.popStateEvents.next({
url: this.url(),
pop: true,
type: "popstate"
});
}
}
);
}
示例5: it
it('should navigate back', async(inject([TestComponentBuilder, ReactNativeRootRenderer], (tcb: TestComponentBuilder, _rootRenderer: ReactNativeRootRenderer) => {
var rootRenderer = _rootRenderer;
var router: Router;
var location: LocationStrategy;
tcb.createAsync(TestComponent).then((fixture: ComponentFixture<TestComponent>) => {
router = fixture.componentInstance.router;
location = fixture.componentInstance.location;
fixture.detectChanges();
rootRenderer.executeCommands();
mock.clearLogs();
return new Promise((resolve: any) => {
setTimeout(() => {
rootRenderer.executeCommands();
expect(mock.commandLogs.toString()).toEqual(
'CREATE+5+cmp-a+{},CREATE+6+native-text+{},CREATE+7+native-rawtext+{"text":"a"},ATTACH+6+7+0,ATTACH+5+6+0,ATTACH+3+5+1');
mock.clearLogs();
router.navigateByUrl('/b')
.then((_: any) => {
rootRenderer.executeCommands();
expect(mock.commandLogs.toString()).toEqual(
'CREATE+8+cmp-b+{},CREATE+9+native-text+{},CREATE+10+native-rawtext+{"text":"b"},DETACH+3+1,ATTACH+3+8+1,ATTACH+9+10+0,ATTACH+8+9+0');
mock.clearLogs();
})
.then((_: any) => {
location.back();
setTimeout(() => {
rootRenderer.executeCommands();
expect(mock.commandLogs.toString()).toEqual(
'CREATE+11+cmp-a+{},CREATE+12+native-text+{},CREATE+13+native-rawtext+{"text":"a"},DETACH+3+1,ATTACH+3+11+1,ATTACH+12+13+0,ATTACH+11+12+0');
resolve();
}, 30);
});
}, 0);
});
});
})));
示例6: tick
.then((_: any) => {
location.back();
tick();
fixture.detectChanges();
rootRenderer.executeCommands();
expect(mock.commandLogs.toString()).toEqual(
'CREATE+11+cmp-a+{},CREATE+12+native-text+{},CREATE+13+native-rawtext+{"text":"a"},DETACH+3+1,ATTACH+3+11+1,ATTACH+12+13+0,ATTACH+11+12+0');
});
示例7: setTimeout
.then((_: any) => {
location.back();
setTimeout(() => {
rootRenderer.executeCommands();
expect(mock.commandLogs.toString()).toEqual(
'CREATE+11+cmp-a+{},CREATE+12+native-text+{},CREATE+13+native-rawtext+{"text":"a"},DETACH+3+1,ATTACH+3+11+1,ATTACH+12+13+0,ATTACH+11+12+0');
resolve();
}, 30);
});
示例8: url
public url( newUrl?: string ) : RetroLocation | string {
// Return the existing url.
if ( newUrl === undefined ) {
return( this.locationStrategy.path( true ) ); // true = Include Hash.
}
// Set the new url.
this.navigate( this.parseUrl( newUrl ) );
return( this );
}
示例9: navigate
// I navigate to the location defined by the given URL segments (pathname, search,
// and hash).
private navigate( urlSegments: UrlSegments ) : void {
var url = urlSegments.pathname;
if ( urlSegments.search ) {
url += ( "?" + urlSegments.search );
}
if ( urlSegments.hash ) {
url += ( "#" + urlSegments.hash );
}
// Only push the state if the URL has actually changed. We only need this
// because the RetroLocation emits an event and we want this event to be a bit
// more closely tied to an actual change in the location.
if ( url !== this.url() ) {
this.locationStrategy.pushState(
// pushState - all the other strategies appear to pass NULL here.
null,
// title - all the other strategies appear to pass empty-string here.
"",
// path - we are encoding the entire location into the path.
url,
// queryParams - we are baking these into the path (above).
""
);
this.popStateEvents.next({
url: url,
pop: true,
type: "popstate"
});
}
}
示例10:
_goBack() {
this._locationStrategy.back();
}