diff --git a/modules/@angular/router/index.ts b/modules/@angular/router/index.ts index c51e9c7102..4ab9b4241e 100644 --- a/modules/@angular/router/index.ts +++ b/modules/@angular/router/index.ts @@ -12,6 +12,9 @@ import {RouterOutlet} from './src/directives/router_outlet'; export {ExtraOptions} from './src/common_router_providers'; export {Data, ResolveData, Route, RouterConfig} from './src/config'; +export {RouterLink, RouterLinkWithHref} from './src/directives/router_link'; +export {RouterLinkActive} from './src/directives/router_link_active'; +export {RouterOutlet} from './src/directives/router_outlet'; export {CanActivate, CanDeactivate, Resolve} from './src/interfaces'; export {Event, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router, RoutesRecognized} from './src/router'; export {RouterOutletMap} from './src/router_outlet_map'; @@ -19,9 +22,7 @@ export {provideRouter} from './src/router_providers'; export {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot} from './src/router_state'; export {PRIMARY_OUTLET, Params} from './src/shared'; export {DefaultUrlSerializer, UrlPathWithParams, UrlSerializer, UrlTree} from './src/url_tree'; -export {RouterLink, RouterLinkWithHref} from './src/directives/router_link'; -export {RouterLinkActive} from './src/directives/router_link_active'; -export {RouterOutlet} from './src/directives/router_outlet'; + /** diff --git a/modules/@angular/router/src/apply_redirects.ts b/modules/@angular/router/src/apply_redirects.ts index d0be8d2977..a517a898d6 100644 --- a/modules/@angular/router/src/apply_redirects.ts +++ b/modules/@angular/router/src/apply_redirects.ts @@ -235,19 +235,28 @@ function split( const s = new UrlSegment( consumedPaths, createChildrenForEmptyPaths(config, new UrlSegment(slicedPath, segment.children))); - return {segment: s, slicedPath: []}; + return {segment: mergeTrivialChildren(s), slicedPath: []}; } else if (slicedPath.length === 0 && containsEmptyPathRedirects(segment, slicedPath, config)) { const s = new UrlSegment( segment.pathsWithParams, addEmptyPathsToChildrenIfNeeded(segment, slicedPath, config, segment.children)); - return {segment: s, slicedPath}; + return {segment: mergeTrivialChildren(s), slicedPath}; } else { return {segment, slicedPath}; } } +function mergeTrivialChildren(s: UrlSegment): UrlSegment { + if (s.numberOfChildren === 1 && s.children[PRIMARY_OUTLET]) { + const c = s.children[PRIMARY_OUTLET]; + return new UrlSegment(s.pathsWithParams.concat(c.pathsWithParams), c.children); + } else { + return s; + } +} + function addEmptyPathsToChildrenIfNeeded( segment: UrlSegment, slicedPath: UrlPathWithParams[], routes: Route[], children: {[name: string]: UrlSegment}): {[name: string]: UrlSegment} { diff --git a/modules/@angular/router/src/url_tree.ts b/modules/@angular/router/src/url_tree.ts index 06d8a150b6..e4ef4b96cd 100644 --- a/modules/@angular/router/src/url_tree.ts +++ b/modules/@angular/router/src/url_tree.ts @@ -96,7 +96,15 @@ export class UrlSegment { forEach(children, (v: any, k: any) => v.parent = this); } - hasChildren(): boolean { return Object.keys(this.children).length > 0; } + /** + * Return true if the segment has child segments + */ + hasChildren(): boolean { return this.numberOfChildren > 0; } + + /** + * Returns the number of child sements. + */ + get numberOfChildren(): number { return Object.keys(this.children).length; } toString(): string { return serializePaths(this); } } diff --git a/modules/@angular/router/test/apply_redirects.spec.ts b/modules/@angular/router/test/apply_redirects.spec.ts index f16ebc1c6d..129cb529b7 100644 --- a/modules/@angular/router/test/apply_redirects.spec.ts +++ b/modules/@angular/router/test/apply_redirects.spec.ts @@ -187,7 +187,7 @@ describe('applyRedirects', () => { }, {path: '', redirectTo: 'a'} ], - '', (t: UrlTree) => { compareTrees(t, tree('a/(b)')); }); + '', (t: UrlTree) => { compareTrees(t, tree('a/b')); }); }); it('redirect to an empty path should work', () => {