feat(router): add isActive to router

This commit is contained in:
vsavkin
2016-07-28 17:59:05 -07:00
parent 2fdb39e60a
commit 5162fb6d52
3 changed files with 21 additions and 7 deletions

View File

@ -31,7 +31,7 @@ import {LoadedRouterConfig, RouterConfigLoader} from './router_config_loader';
import {RouterOutletMap} from './router_outlet_map';
import {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot, advanceActivatedRoute, createEmptyState} from './router_state';
import {PRIMARY_OUTLET, Params} from './shared';
import {UrlSerializer, UrlTree, createEmptyUrlTree} from './url_tree';
import {UrlSerializer, UrlTree, containsTree, createEmptyUrlTree} from './url_tree';
import {andObservables, forEach, merge, shallowEqual, waitForMap, wrapIntoObservable} from './utils/collection';
import {TreeNode} from './utils/tree';
@ -305,6 +305,18 @@ export class Router {
*/
parseUrl(url: string): UrlTree { return this.urlSerializer.parse(url); }
/**
* Returns if the url is activated or not.
*/
isActive(url: string|UrlTree, exact: boolean): boolean {
if (url instanceof UrlTree) {
return containsTree(this.currentUrlTree, url, exact);
} else {
const urlTree = this.urlSerializer.parse(url);
return containsTree(this.currentUrlTree, urlTree, exact);
}
}
private scheduleNavigation(url: UrlTree, preventPushState: boolean): Promise<boolean> {
const id = ++this.navigationId;
this.routerEvents.next(new NavigationStart(id, this.serializeUrl(url)));