當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Router.initialNavigation方法代碼示例

本文整理匯總了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');
      });
  }));
開發者ID:angular,項目名稱:react-native-renderer,代碼行數:31,代碼來源:router_spec.ts

示例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);
 });
開發者ID:SrgGs,項目名稱:ng-zorro-antd,代碼行數:29,代碼來源:nz-breadcrumb.spec.ts

示例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();
  }));
開發者ID:woocommerce-quiz,項目名稱:comixed,代碼行數:29,代碼來源:app.component.spec.ts

示例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();

  });
開發者ID:ianasjl,項目名稱:real-chat,代碼行數:35,代碼來源:app.component.spec.ts

示例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]);
 });
開發者ID:OlivierCoue,項目名稱:invow,代碼行數:8,代碼來源:tc-app.component.ts

示例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;
 },
開發者ID:martinsvb,項目名稱:Angular2_bootstrap_seed,代碼行數:10,代碼來源:app.component.spec.ts

示例7: createRootWithRouter

export function createRootWithRouter(
  router: Router,
  type: any,
): ComponentFixture<any> {
  const f = TestBed.createComponent(type);
  advance(f);
  router.initialNavigation();
  advance(f);
  return f;
}
開發者ID:catrielmuller,項目名稱:angulartics2,代碼行數:10,代碼來源:test.mocks.ts

示例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();
}
開發者ID:BobChao87,項目名稱:angular,代碼行數:15,代碼來源:app.component.router.spec.ts

示例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);

  }));
開發者ID:ianasjl,項目名稱:real-chat,代碼行數:46,代碼來源:home.component.spec.ts


注:本文中的@angular/router.Router.initialNavigation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。