fix(angular): NavController works with nested outlets (#28421)

Issue number: resolves #28417

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

The common `IonRouterOutlet` was trying to inject another common
`IonRouterOutlet` into `parentOutlet`:
dc94ae01fe/packages/angular/common/src/directives/navigation/router-outlet.ts (L119)
None existed, so this field was `null`.

This is a problem if developers are using the module `IonRouterOutlet`
since parent router outlets will not be currently injected because
Angular is trying to use the common `IonRouterOutlet` not the module
`IonRouterOutlet`:
https://github.com/ionic-team/ionic-framework/blob/main/packages/angular/src/directives/navigation/ion-router-outlet.ts.
The same goes for the standalone `IonRouterOutlet`.

This resulted in things such as `NavController.pop` not working in
nested outlets because the parentOutlet was not defined.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- `IonRouterOutlet` now injects the correct router outlet instance for
`parentOutlet`

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.5.3-dev.11698328998.1a79f815`
This commit is contained in:
Liam DeBeasi
2023-10-27 09:17:42 -04:00
committed by GitHub
parent a5c68aa529
commit 90acad1837
7 changed files with 73 additions and 4 deletions

View File

@ -4,4 +4,7 @@
<ion-button routerLink="/lazy/tabs" id="goto-tabs">Go To Tabs</ion-button>
<ion-button routerLink="/lazy/nested-outlet/page2" id="goto-nested-page2">Go To SECOND</ion-button>
</p>
<p id="parent-outlet">
Has Parent Outlet: <span>{{ hasParentOutlet }}</span>
</p>
</ion-content>

View File

@ -1,10 +1,16 @@
import { Component, NgZone, OnDestroy, OnInit } from '@angular/core';
import { IonRouterOutlet } from '@ionic/angular';
@Component({
selector: 'app-nested-outlet-page',
templateUrl: './nested-outlet-page.component.html',
})
export class NestedOutletPageComponent implements OnDestroy, OnInit {
hasParentOutlet = false;
constructor(private routerOutlet: IonRouterOutlet) {
this.hasParentOutlet = routerOutlet.parentOutlet != null;
}
ngOnInit() {
NgZone.assertInAngularZone();

View File

@ -1,12 +1,21 @@
import { Component } from '@angular/core';
import { IonRouterOutlet } from '@ionic/angular/standalone';
@Component({
selector: 'app-tab-one',
template: `
Tab 1
<p id="parent-outlet">
Has Parent Outlet: <span>{{ hasParentOutlet }}</span>
</p>
`,
standalone: true,
})
export class TabOneComponent {
hasParentOutlet = false;
constructor(private routerOutlet: IonRouterOutlet) {
this.hasParentOutlet = routerOutlet.parentOutlet != null;
}
}