本文整理汇总了TypeScript中@angular/router.Router.initialNavigation方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Router.initialNavigation方法的具体用法?TypeScript Router.initialNavigation怎么用?TypeScript Router.initialNavigation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/router.Router
的用法示例。
在下文中一共展示了Router.initialNavigation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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');
});
}));
示例2: flush
fixture.ngZone.run(() => {
router = TestBed.get(Router);
router.initialNavigation();
// Generate breadcrumb items.
router.navigate([ 'one', 'two', 'three', 'four' ]);
fixture.detectChanges();
flush();
fixture.detectChanges();
items = fixture.debugElement.queryAll(By.directive(NzBreadCrumbItemComponent));
// Should generate 2 breadcrumbs when reaching out of the `data` scope.
expect(breadcrumb.componentInstance.breadcrumbs.length).toBe(2);
dispatchMouseEvent(items[ 1 ].nativeElement.querySelector('a'), 'click');
router.navigate([ 'one', 'two', 'three' ]);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(breadcrumb.componentInstance.breadcrumbs.length).toBe(2);
router.navigate([ 'one', 'two' ]);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(breadcrumb.componentInstance.breadcrumbs.length).toBe(1);
router.navigate([ 'one' ]);
fixture.detectChanges();
flush();
fixture.detectChanges();
// Shouldn't generate breadcrumb at all.
expect(breadcrumb.componentInstance.breadcrumbs.length).toBe(0);
});
示例3: beforeEach
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
HttpClientModule,
LoadingModule
],
declarations: [
BusyIndicatorComponent,
AppComponent
],
providers: [
AlertService,
{ provide: UserService, useClass: MockUserService },
{ provide: ComicService, useClass: MockComicService },
],
}).compileComponents();
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
user_service = TestBed.get(UserService);
alert_service = TestBed.get(AlertService);
comic_service = TestBed.get(ComicService);
router = TestBed.get(Router);
fixture.detectChanges();
router.initialNavigation();
}));
示例4: beforeEach
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent,
LoginComponent,
HomeComponent
],
imports: [
BrowserModule,
HttpModule,
FormsModule,
BrowserAnimationsModule,
MatCheckboxModule,
MatTabsModule,
MatGridListModule,
MatToolbarModule,
FlexLayoutModule,
MatCardModule,
MatInputModule,
Ng2SearchPipeModule,
MatSidenavModule,
RouterModule,
RouterTestingModule.withRoutes(appRoutes),
],
providers: [{ provide: APP_BASE_HREF, useValue: '/' }
],
});
router = TestBed.get(Router);
location = TestBed.get(Location);
fixture = TestBed.createComponent(AppComponent);
router.initialNavigation();
});
示例5:
authService.initCurrentUser().then(success => {
router.initialNavigation();
url = url.replace("#_=_", "");
if(url != '/' && url != '/discover')
this.router.navigate([url, params]);
if(this.authService.isLoggedIn && url == '/')
this.router.navigate([url]);
});
示例6: Router
useFactory: (
resolver:ComponentResolver,
urlSerializer:UrlSerializer,
outletMap:RouterOutletMap,
location:Location,
injector:Injector) => {
const r = new Router(TestComponent, resolver, urlSerializer, outletMap, location, injector, config);
r.initialNavigation();
return r;
},
示例7: createRootWithRouter
export function createRootWithRouter(
router: Router,
type: any,
): ComponentFixture<any> {
const f = TestBed.createComponent(type);
advance(f);
router.initialNavigation();
advance(f);
return f;
}
示例8: createComponent
function createComponent() {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
const injector = fixture.debugElement.injector;
location = injector.get(Location) as SpyLocation;
router = injector.get(Router);
router.initialNavigation();
spyOn(injector.get(TwainService), 'getQuote')
// fake fast async observable
.and.returnValue(asyncData('Test Quote'));
advance();
page = new Page();
}
示例9: beforeEach
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [
FormsModule,
HttpModule,
Ng2SearchPipeModule,
RouterTestingModule.withRoutes(appRoutes)
],
providers: [
ChatService,
HttpService,
MockBackend,
BaseRequestOptions,
{
provide: Jsonp,
useFactory: (backend, options) => new Jsonp(backend, options),
deps: [MockBackend, BaseRequestOptions]
},
{
provide: Http,
useFactory: (backend, options) => new Http(backend, options),
deps: [MockBackend, BaseRequestOptions]
}
],
declarations: [ HomeComponent, LoginComponent]
});
router = TestBed.get(Router);
location = TestBed.get(Location);
fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
router.initialNavigation();
backend = TestBed.get(MockBackend);
service = TestBed.get(ChatService);
}));