Skip to content

Commit

Permalink
fix(UndefinedRoutes): Route view correctly ignores undefined routes (#60
Browse files Browse the repository at this point in the history
)
  • Loading branch information
MikeRyanDev authored and brandonroberts committed Apr 19, 2016
1 parent c048a51 commit 1cdb67a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/route-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import { ComponentRenderer } from './component-renderer';
export class RouteView implements OnDestroy, OnInit {
private _prev: ComponentRef;
private _sub: any;
private _routeSetProvider = provide(RouterInstruction, {
useValue: this._routeSet$.map<NextInstruction>(set => {
private _routerInstructionProvider = provide(RouterInstruction, {
useValue: this._routerInstruction$.map<NextInstruction>(set => {
return {
locationChange: set.locationChange,
routeConfigs: [ ...set.routeConfigs ].slice(1),
Expand All @@ -49,15 +49,15 @@ export class RouteView implements OnDestroy, OnInit {

constructor(
@Attribute('name') private _name: string,
protected _routeSet$: RouterInstruction,
protected _routerInstruction$: RouterInstruction,
protected _injector: Injector,
protected _renderer: ComponentRenderer,
protected _dcl: DynamicComponentLoader,
protected _ref: ElementRef
) { }

ngOnInit() {
this._sub = this._routeSet$
this._sub = this._routerInstruction$
.map(set => {
const route = set.routeConfigs[0];
const components = getNamedComponents(route, this._name);
Expand All @@ -71,7 +71,7 @@ export class RouteView implements OnDestroy, OnInit {
.do(ins => this._cleanPreviousRef())
.filter(({ components }) => !!components.component || !!components.loadComponent)
.switchMap(({ route, components }) => this._renderer.render(
route, components, this._injector, this._ref, this._dcl, [ this._routeSetProvider ]
route, components, this._injector, this._ref, this._dcl, [ this._routerInstructionProvider ]
))
.subscribe((ref: ComponentRef) => this._prev = ref);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface Route extends IndexRoute {
export const ROUTES = new OpaqueToken('@ngrx/router Init Routes');

export function getNamedComponents(route: IndexRoute, name?: string): BaseRoute {
if (!route) {
return { component: null, loadComponent: null };
}

if (!name) {
return { component: route.component, loadComponent: route.loadComponent };
}
Expand Down
7 changes: 7 additions & 0 deletions spec/route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@ describe('Route', function() {
expect(resolved.component).toBe(FixtureB);
expect(resolved.loadComponent).toBe(FixctureD);
});

it('should return null for undefined routes', function() {
const resolved = getNamedComponents(undefined, 'main');

expect(resolved.component).toBe(null);
expect(resolved.loadComponent).toBe(null);
});
});
});

0 comments on commit 1cdb67a

Please sign in to comment.