Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions packages/angular/src/directives/navigation/ion-router-outlet.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { Directive } from '@angular/core';
import { Location } from '@angular/common';
import { Directive, Attribute, Optional, SkipSelf, ElementRef, NgZone } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { IonRouterOutlet as IonRouterOutletBase } from '@ionic/angular/common';

@Directive({
selector: 'ion-router-outlet',
})
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export class IonRouterOutlet extends IonRouterOutletBase {}
export class IonRouterOutlet extends IonRouterOutletBase {
/**
* We need to pass in the correct instance of IonRouterOutlet
* otherwise parentOutlet will be null in a nested outlet context.
* This results in APIs such as NavController.pop not working
* in nested outlets because the parent outlet cannot be found.
*/
constructor(
@Attribute('name') name: string,
@Optional() @Attribute('tabs') tabs: string,
commonLocation: Location,
elementRef: ElementRef,
router: Router,
zone: NgZone,
activatedRoute: ActivatedRoute,
@SkipSelf() @Optional() readonly parentOutlet?: IonRouterOutlet
) {
super(name, tabs, commonLocation, elementRef, router, zone, activatedRoute, parentOutlet);
}
}
25 changes: 23 additions & 2 deletions packages/angular/standalone/src/navigation/router-outlet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Directive } from '@angular/core';
import { Location } from '@angular/common';
import { Directive, Attribute, Optional, SkipSelf, ElementRef, NgZone } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { IonRouterOutlet as IonRouterOutletBase, ProxyCmp } from '@ionic/angular/common';
import { defineCustomElement } from '@ionic/core/components/ion-router-outlet.js';

Expand All @@ -10,4 +12,23 @@ import { defineCustomElement } from '@ionic/core/components/ion-router-outlet.js
standalone: true,
})
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export class IonRouterOutlet extends IonRouterOutletBase {}
export class IonRouterOutlet extends IonRouterOutletBase {
/**
* We need to pass in the correct instance of IonRouterOutlet
* otherwise parentOutlet will be null in a nested outlet context.
* This results in APIs such as NavController.pop not working
* in nested outlets because the parent outlet cannot be found.
*/
constructor(
@Attribute('name') name: string,
@Optional() @Attribute('tabs') tabs: string,
commonLocation: Location,
elementRef: ElementRef,
router: Router,
zone: NgZone,
activatedRoute: ActivatedRoute,
@SkipSelf() @Optional() readonly parentOutlet?: IonRouterOutlet
) {
super(name, tabs, commonLocation, elementRef, router, zone, activatedRoute, parentOutlet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ describe('Nested Outlet', () => {
cy.get('#goto-nested-page2').click();
});

// Fixes https://github.com/ionic-team/ionic-framework/issues/28417
it('parentOutlet should be defined', () => {
Comment thread
liamdebeasi marked this conversation as resolved.
cy.get('#parent-outlet span').should('have.text', 'true');
});
});

5 changes: 5 additions & 0 deletions packages/angular/test/base/e2e/src/standalone/tabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ describe('Tabs', () => {
cy.get('app-tab-two').should('be.visible');
cy.contains('Tab 2');
});

// Fixes https://github.com/ionic-team/ionic-framework/issues/28417
it('parentOutlet should be defined', () => {
Comment thread
liamdebeasi marked this conversation as resolved.
cy.get('#parent-outlet span').should('have.text', 'true');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ <h1>Nested page 1</h1>
<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>
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}