fix(router): fix router to handle guards that return observable

Closes #19
This commit is contained in:
vsavkin
2016-06-06 10:55:12 -07:00
parent 9b356d9b86
commit 5742d4720a
2 changed files with 65 additions and 5 deletions

View File

@ -320,9 +320,9 @@ class GuardChecks {
return forkJoin(canActivate.map(c => {
const guard = this.injector.get(c);
if (guard.canActivate) {
return of(guard.canActivate(future, this.future));
return wrapIntoObservable(guard.canActivate(future, this.future));
} else {
return of(guard(future, this.future));
return wrapIntoObservable(guard(future, this.future));
}
})).map(and);
}
@ -333,14 +333,22 @@ class GuardChecks {
return forkJoin(canDeactivate.map(c => {
const guard = this.injector.get(c);
if (guard.canDeactivate) {
return of(guard.canDeactivate(component, curr, this.curr));
return wrapIntoObservable(guard.canDeactivate(component, curr, this.curr));
} else {
return of(guard(component, curr, this.curr));
return wrapIntoObservable(guard(component, curr, this.curr));
}
})).map(and);
}
}
function wrapIntoObservable<T>(value: T | Observable<T>): Observable<T> {
if (value instanceof Observable) {
return value;
} else {
return of(value);
}
}
class ActivateRoutes {
constructor(private futureState: RouterState, private currState: RouterState) {}