Skip to content

Commit

Permalink
fix: pages are mounted inside of router outlet correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
liamdebeasi committed Jan 29, 2024
1 parent 0e54034 commit 5a68a08
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
24 changes: 9 additions & 15 deletions packages/angular/common/src/directives/navigation/router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ViewContainerRef,
inject,
Attribute,
Component,
Directive,
EventEmitter,
Optional,
Output,
Expand All @@ -35,13 +35,14 @@ import { RouteView, StackDidChangeEvent, StackWillChangeEvent, getUrl, isTabSwit

// TODO(FW-2827): types

@Component({
@Directive({
selector: 'ion-router-outlet',
template: '<ng-container #outletContent><ng-content></ng-content></ng-container>',
exportAs: 'outlet',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['animated', 'animation', 'mode', 'swipeGesture'],
})
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export abstract class IonRouterOutlet implements OnDestroy, OnInit {

abstract outletContent: any;

nativeEl: HTMLIonRouterOutletElement;
Expand Down Expand Up @@ -117,20 +118,13 @@ export abstract class IonRouterOutlet implements OnDestroy, OnInit {
router: Router,
zone: NgZone,
activatedRoute: ActivatedRoute,
protected outletContentContainer: ViewContainerRef,
@SkipSelf() @Optional() readonly parentOutlet?: IonRouterOutlet
) {
this.nativeEl = elementRef.nativeElement;
this.name = name || PRIMARY_OUTLET;
this.tabsPrefix = tabs === 'true' ? getUrl(router, activatedRoute) : undefined;
this.stackCtrl = new StackController(this.tabsPrefix, this.nativeEl, router, this.navCtrl, zone, commonLocation);
this.parentContexts.onChildOutletCreated(this.name, this as any);

console.log('looking at container', this.outletContentContainer)

setTimeout(() => {
console.log('in timeout', this.outletContentContainer)
}, 500);
}

ngOnDestroy(): void {
Expand Down Expand Up @@ -288,12 +282,12 @@ export abstract class IonRouterOutlet implements OnDestroy, OnInit {
* View components need to be added as a child of ion-router-outlet
* for page transitions and swipe to go back.
* However, createComponent mounts components as siblings of the
* ViewContainerRef. As a result, outletContentContainer must reference
* ViewContainerRef. As a result, outletContent must reference
* an ng-container inside of ion-router-outlet and not
* ion-router-outlet itself.
*/
cmpRef = this.activated = this.outletContentContainer.createComponent(component, {
index: this.outletContentContainer.length,
cmpRef = this.activated = this.outletContent.createComponent(component, {
index: this.outletContent.length,
injector,
environmentInjector: environmentInjector ?? this.environmentInjector,
});
Expand All @@ -303,7 +297,7 @@ export abstract class IonRouterOutlet implements OnDestroy, OnInit {

// Calling `markForCheck` to make sure we will run the change detection when the
// `RouterOutlet` is inside a `ChangeDetectionStrategy.OnPush` component.
enteringView = this.stackCtrl.createView(this.activated, activatedRoute);
enteringView = this.stackCtrl.createView(this.activated!, activatedRoute);

Check warning on line 300 in packages/angular/common/src/directives/navigation/router-outlet.ts

View workflow job for this annotation

GitHub Actions / build-angular

Forbidden non-null assertion

// Store references to the proxy by component
this.proxyMap.set(cmpRef.instance, activatedRouteProxy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ export class IonRouterOutlet extends IonRouterOutletBase {
router: Router,
zone: NgZone,
activatedRoute: ActivatedRoute,
outletContent: ViewContainerRef,
@SkipSelf() @Optional() readonly parentOutlet?: IonRouterOutlet
) {
console.log('lookiehere', outletContent)
setTimeout(() => {
console.log('tst2',outletContent)
}, 500);
super(name, tabs, commonLocation, elementRef, router, zone, activatedRoute, outletContent, parentOutlet);
super(name, tabs, commonLocation, elementRef, router, zone, activatedRoute, parentOutlet);
}
}
7 changes: 1 addition & 6 deletions packages/angular/standalone/src/navigation/router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@ export class IonRouterOutlet extends IonRouterOutletBase {
router: Router,
zone: NgZone,
activatedRoute: ActivatedRoute,
outletContent: ViewContainerRef,
@SkipSelf() @Optional() readonly parentOutlet?: IonRouterOutlet
) {
console.log('lookiehere', outletContent)
setTimeout(() => {
console.log('tst2',outletContent)
}, 500);
super(name, tabs, commonLocation, elementRef, router, zone, activatedRoute, outletContent, parentOutlet);
super(name, tabs, commonLocation, elementRef, router, zone, activatedRoute, parentOutlet);
}
}

0 comments on commit 5a68a08

Please sign in to comment.