feat(router): guard returning UrlTree cancels current navigation and redirects (#26521)

Fixes #24618
FW-153 #resolve

PR Close #26521
This commit is contained in:
Jason Aden
2018-10-17 09:30:45 -07:00
committed by Matias Niemelä
parent 081f95c812
commit 4e9f2e5895
8 changed files with 116 additions and 23 deletions

View File

@ -17,7 +17,7 @@ import {ActivatedRouteSnapshot, RouterStateSnapshot} from '../router_state';
import {UrlTree} from '../url_tree';
import {wrapIntoObservable} from '../utils/collection';
import {CanActivate, CanDeactivate, getCanActivateChild, getToken} from '../utils/preactivation';
import {isCanActivate, isCanActivateChild, isCanDeactivate, isFunction, isBoolean} from '../utils/type_guards';
import {isBoolean, isCanActivate, isCanActivateChild, isCanDeactivate, isFunction} from '../utils/type_guards';
import {prioritizedGuardValue} from './prioritized_guard_value';

View File

@ -7,9 +7,10 @@
*/
import {Observable, OperatorFunction, combineLatest} from 'rxjs';
import {filter, scan, startWith, switchMap, take} from 'rxjs/operators';
import {filter, map, scan, startWith, switchMap, take} from 'rxjs/operators';
import {UrlTree} from '../url_tree';
import {isUrlTree} from '../utils/type_guards';
const INITIAL_VALUE = Symbol('INITIAL_VALUE');
declare type INTERIM_VALUES = typeof INITIAL_VALUE | boolean | UrlTree;
@ -38,7 +39,7 @@ export function prioritizedGuardValue():
// navigation
if (val === false) return val;
if (i === list.length - 1 || val instanceof UrlTree) {
if (i === list.length - 1 || isUrlTree(val)) {
return val;
}
}
@ -47,6 +48,8 @@ export function prioritizedGuardValue():
}, acc);
},
INITIAL_VALUE),
filter(item => item !== INITIAL_VALUE), take(1)) as Observable<boolean|UrlTree>;
filter(item => item !== INITIAL_VALUE),
map(item => isUrlTree(item) ? item : item === true), //
take(1)) as Observable<boolean|UrlTree>;
});
}