|
8 | 8 |
|
9 | 9 | import {CommonModule, Location} from '@angular/common'; |
10 | 10 | import {SpyLocation} from '@angular/common/testing'; |
11 | | -import {ChangeDetectionStrategy, Component, Injectable, NgModule, NgModuleFactoryLoader, NgModuleRef, NgZone, OnDestroy, ɵConsole as Console, ɵNoopNgZone as NoopNgZone} from '@angular/core'; |
| 11 | +import {ChangeDetectionStrategy, Component, Injectable, NgModule, NgModuleFactoryLoader, NgModuleRef, NgZone, OnDestroy, ViewChild, ɵConsole as Console, ɵNoopNgZone as NoopNgZone} from '@angular/core'; |
12 | 12 | import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing'; |
| 13 | +import {describe} from '@angular/core/testing/src/testing_internal'; |
13 | 14 | import {By} from '@angular/platform-browser/src/dom/debug/by'; |
14 | 15 | import {expect} from '@angular/platform-browser/testing/src/matchers'; |
15 | | -import {ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DefaultUrlSerializer, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, Navigation, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ParamMap, Params, PreloadAllModules, PreloadingStrategy, PRIMARY_OUTLET, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, Router, RouteReuseStrategy, RouterEvent, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlSerializer, UrlTree} from '@angular/router'; |
| 16 | +import {ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DefaultUrlSerializer, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, Navigation, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ParamMap, Params, PreloadAllModules, PreloadingStrategy, PRIMARY_OUTLET, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, Router, RouteReuseStrategy, RouterEvent, RouterLink, RouterLinkWithHref, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlSerializer, UrlTree} from '@angular/router'; |
16 | 17 | import {EMPTY, Observable, Observer, of, Subscription} from 'rxjs'; |
17 | 18 | import {delay, filter, first, map, mapTo, tap} from 'rxjs/operators'; |
18 | 19 |
|
@@ -5382,6 +5383,53 @@ describe('Integration', () => { |
5382 | 5383 | }))); |
5383 | 5384 | }); |
5384 | 5385 |
|
| 5386 | + it('can use `relativeTo` `route.parent` in `routerLink` to close secondary outlet', |
| 5387 | + fakeAsync(() => { |
| 5388 | + // Given |
| 5389 | + @Component({template: '<router-outlet name="secondary"></router-outlet>'}) |
| 5390 | + class ChildRootCmp { |
| 5391 | + } |
| 5392 | + |
| 5393 | + @Component({ |
| 5394 | + selector: 'link-cmp', |
| 5395 | + template: |
| 5396 | + `<a [relativeTo]="route.parent" [routerLink]="[{outlets: {'secondary': null}}]">link</a> |
| 5397 | + <button [relativeTo]="route.parent" [routerLink]="[{outlets: {'secondary': null}}]">link</button> |
| 5398 | + ` |
| 5399 | + }) |
| 5400 | + class RelativeLinkCmp { |
| 5401 | + @ViewChild(RouterLink) buttonLink!: RouterLink; |
| 5402 | + @ViewChild(RouterLinkWithHref) aLink!: RouterLink; |
| 5403 | + |
| 5404 | + constructor(readonly route: ActivatedRoute) {} |
| 5405 | + } |
| 5406 | + @NgModule({ |
| 5407 | + declarations: [RelativeLinkCmp, ChildRootCmp], |
| 5408 | + imports: [RouterModule.forChild([{ |
| 5409 | + path: 'childRoot', |
| 5410 | + component: ChildRootCmp, |
| 5411 | + children: [ |
| 5412 | + {path: 'popup', outlet: 'secondary', component: RelativeLinkCmp}, |
| 5413 | + ] |
| 5414 | + }])] |
| 5415 | + }) |
| 5416 | + class LazyLoadedModule { |
| 5417 | + } |
| 5418 | + const router = TestBed.inject(Router); |
| 5419 | + router.resetConfig([{path: 'root', loadChildren: () => LazyLoadedModule}]); |
| 5420 | + |
| 5421 | + // When |
| 5422 | + router.navigateByUrl('/root/childRoot/(secondary:popup)'); |
| 5423 | + const fixture = createRoot(router, RootCmp); |
| 5424 | + advance(fixture); |
| 5425 | + |
| 5426 | + // Then |
| 5427 | + const relativeLinkCmp = |
| 5428 | + fixture.debugElement.query(By.directive(RelativeLinkCmp)).componentInstance; |
| 5429 | + expect(relativeLinkCmp.aLink.urlTree.toString()).toEqual('/root/childRoot'); |
| 5430 | + expect(relativeLinkCmp.buttonLink.urlTree.toString()).toEqual('/root/childRoot'); |
| 5431 | + })); |
| 5432 | + |
5385 | 5433 | describe('relativeLinkResolution', () => { |
5386 | 5434 | @Component({selector: 'link-cmp', template: `<a [routerLink]="['../simple']">link</a>`}) |
5387 | 5435 | class RelativeLinkCmp { |
|
0 commit comments