mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
refactor(external-router): remove the external router controller, move the reconciliation methods to the nav itself, and move the external activation status information to ion-app
This commit is contained in:
@ -28,7 +28,7 @@ import { OutletInjector } from './outlet-injector';
|
||||
import { RouteEventHandler } from './route-event-handler';
|
||||
|
||||
import { AngularComponentMounter, AngularEscapeHatch } from '..';
|
||||
import { ensureExternalRounterController } from '../util/util';
|
||||
import { getIonApp } from '../util/util';
|
||||
|
||||
let id = 0;
|
||||
|
||||
@ -139,9 +139,14 @@ export class RouterOutlet implements OnDestroy, OnInit, RouterDelegate {
|
||||
export function activateRoute(navElement: HTMLIonNavElement,
|
||||
component: Type<any>, data: any = {}, cfr: ComponentFactoryResolver, injector: Injector, isTopLevel: boolean): Promise<void> {
|
||||
|
||||
return ensureExternalRounterController().then((externalRouterController) => {
|
||||
return getIonApp().then((ionApp) => {
|
||||
if (!ionApp) {
|
||||
return Promise.reject(new Error(`<ion-app> element is required for angular router integration`));
|
||||
}
|
||||
const escapeHatch = getEscapeHatch(cfr, injector);
|
||||
return externalRouterController.reconcileNav(navElement, component, data, escapeHatch, isTopLevel);
|
||||
return navElement.componentOnReady().then(() => {
|
||||
return navElement.reconcileFromExternalRouter(component, data, escapeHatch, isTopLevel);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import {
|
||||
Router
|
||||
} from '@angular/router';
|
||||
|
||||
import { ensureExternalRounterController } from '../util/util';
|
||||
import { getIonApp } from '../util/util';
|
||||
|
||||
@Injectable()
|
||||
export class RouteEventHandler {
|
||||
@ -14,16 +14,16 @@ export class RouteEventHandler {
|
||||
|
||||
router.events.subscribe((event: Event) => {
|
||||
if (event instanceof NavigationEnd) {
|
||||
ensureExternalRounterController().then((element) => {
|
||||
element.updateExternalNavOccuring(false);
|
||||
getIonApp().then((appElement) => {
|
||||
appElement.updateExternalNavOccuring(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
externalNavStart() {
|
||||
return ensureExternalRounterController().then((element) => {
|
||||
element.updateExternalNavOccuring(true);
|
||||
return getIonApp().then((appElement) => {
|
||||
appElement.updateExternalNavOccuring(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,7 @@ export function isString(something: any) {
|
||||
return typeof something === 'string' ? true : false;
|
||||
}
|
||||
|
||||
export function ensureExternalRounterController(): Promise<HTMLIonExternalRouterControllerElement> {
|
||||
const element = document.querySelector('ion-external-router-controller');
|
||||
if (element) {
|
||||
return (element as any).componentOnReady();
|
||||
}
|
||||
const toCreate = document.createElement('ion-external-router-controller');
|
||||
document.body.appendChild(toCreate);
|
||||
return (toCreate as any).componentOnReady();
|
||||
export function getIonApp(): Promise<HTMLIonAppElement> {
|
||||
const element = ensureElementInBody('ion-app') as HTMLIonAppElement;
|
||||
return element.componentOnReady();
|
||||
}
|
Reference in New Issue
Block a user