parent
9b094e42a3
commit
793ac3f6b4
|
@ -37,8 +37,7 @@ export function provideRouter(config: RouterConfig):any[] {
|
|||
throw new Error("Bootstrap at least one component before injecting Router.");
|
||||
}
|
||||
const componentType = ref.componentTypes[0];
|
||||
const r = new Router(componentType, resolver, urlSerializer, outletMap, location, injector);
|
||||
r.resetConfig(config);
|
||||
const r = new Router(componentType, resolver, urlSerializer, outletMap, location, injector, config);
|
||||
ref.registerDisposeListener(() => r.dispose());
|
||||
return r;
|
||||
},
|
||||
|
|
|
@ -54,7 +54,6 @@ export type Event = NavigationStart | NavigationEnd | NavigationCancel | Navigat
|
|||
export class Router {
|
||||
private currentUrlTree: UrlTree;
|
||||
private currentRouterState: RouterState;
|
||||
private config: RouterConfig;
|
||||
private locationSubscription: Subscription;
|
||||
private routerEvents: Subject<Event>;
|
||||
private navigationId: number = 0;
|
||||
|
@ -62,7 +61,7 @@ export class Router {
|
|||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(private rootComponentType:Type, private resolver: ComponentResolver, private urlSerializer: UrlSerializer, private outletMap: RouterOutletMap, private location: Location, private injector: Injector) {
|
||||
constructor(private rootComponentType:Type, private resolver: ComponentResolver, private urlSerializer: UrlSerializer, private outletMap: RouterOutletMap, private location: Location, private injector: Injector, private config: RouterConfig) {
|
||||
this.routerEvents = new Subject<Event>();
|
||||
this.currentUrlTree = createEmptyUrlTree();
|
||||
this.currentRouterState = createEmptyState(rootComponentType);
|
||||
|
|
|
@ -18,23 +18,40 @@ import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'
|
|||
import { ComponentResolver } from '@angular/core';
|
||||
import { SpyLocation } from '@angular/common/testing';
|
||||
import { UrlSerializer, DefaultUrlSerializer, RouterOutletMap, Router, ActivatedRoute, ROUTER_DIRECTIVES, Params,
|
||||
RouterStateSnapshot, ActivatedRouteSnapshot, CanActivate, CanDeactivate, Event, NavigationStart, NavigationEnd, NavigationCancel, NavigationError } from '../src/index';
|
||||
RouterStateSnapshot, ActivatedRouteSnapshot, CanActivate, CanDeactivate, Event, NavigationStart, NavigationEnd, NavigationCancel, NavigationError, RouterConfig } from '../src/index';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
describe("Integration", () => {
|
||||
beforeEachProviders(() => [
|
||||
|
||||
beforeEachProviders(() => {
|
||||
let config: RouterConfig = [
|
||||
{ path: 'simple', component: SimpleCmp }
|
||||
];
|
||||
|
||||
return [
|
||||
RouterOutletMap,
|
||||
{provide: UrlSerializer, useClass: DefaultUrlSerializer},
|
||||
{provide: Location, useClass: SpyLocation},
|
||||
{
|
||||
provide: Router,
|
||||
useFactory: (resolver, urlSerializer, outletMap, location, injector) =>
|
||||
new Router(RootCmp, resolver, urlSerializer, outletMap, location, injector),
|
||||
new Router(RootCmp, resolver, urlSerializer, outletMap, location, injector, config),
|
||||
deps: [ComponentResolver, UrlSerializer, RouterOutletMap, Location, Injector]
|
||||
},
|
||||
{provide: ActivatedRoute, useFactory: (r) => r.routerState.root, deps: [Router]},
|
||||
]);
|
||||
];
|
||||
});
|
||||
|
||||
it('should navigate with a provided config',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
router.navigateByUrl('/simple');
|
||||
advance(fixture);
|
||||
expect(location.path()).toEqual('/simple');
|
||||
})));
|
||||
|
||||
|
||||
it('should update location when navigating',
|
||||
|
|
Loading…
Reference in New Issue