diff --git a/modules/@angular/router/src/common_router_providers.ts b/modules/@angular/router/src/common_router_providers.ts index 54842fa465..6442df813f 100644 --- a/modules/@angular/router/src/common_router_providers.ts +++ b/modules/@angular/router/src/common_router_providers.ts @@ -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; }, diff --git a/modules/@angular/router/src/router.ts b/modules/@angular/router/src/router.ts index 9f1e73f185..e4f596e403 100644 --- a/modules/@angular/router/src/router.ts +++ b/modules/@angular/router/src/router.ts @@ -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; 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(); this.currentUrlTree = createEmptyUrlTree(); this.currentRouterState = createEmptyState(rootComponentType); diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts index b0f012f74c..71fcd3c177 100644 --- a/modules/@angular/router/test/router.spec.ts +++ b/modules/@angular/router/test/router.spec.ts @@ -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(() => [ - 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), - deps: [ComponentResolver, UrlSerializer, RouterOutletMap, Location, Injector] - }, - {provide: ActivatedRoute, useFactory: (r) => r.routerState.root, deps: [Router]}, - ]); + + 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, 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', @@ -42,7 +59,7 @@ describe("Integration", () => { router.resetConfig([ { path: 'team/:id', component: TeamCmp } ]); - + const fixture = tcb.createFakeAsync(RootCmp); advance(fixture);