OK, this goes beyond just the deep linker, but I remain cautiously optimistic that @rlouie’s goal might still be attainable. I am now looking at module-loader, and it seems to have a map of components to modules/component factory resolvers that can handle them. If one module really can provide multiple components, I’m hopeful that the same resolver can properly resolve requests for any of them.
So, IonicPageModule.forChild()
under the hood associates an arbitrary injection token with its argument. The module loader unpacks that and uses it to populate the cfr map. What if it were allowed to be an array of classes, so one could write:
import IonicPageModule.forChild([ComponentA, ComponentB])
The module loader could detect this and loop through the array, doing what it is currently doing on line 46:
this._cfrMap.set(component, ref.componentFactoryResolver);
…for each component in the array. That might work. I’m not sure how to run against a local dev Ionic build, though. I remember that not going real great the last time I tried it.
UPDATE: that sort of worked, but not really, because now that component array is coming in as the argument to the resolver, which is choking it.
FURTHER UPDATE: OK, I have a hacked-up PoC that does seem to work. Obviously, don’t try this at home if you’re not willing to break things. I took the conference app and folded the SpeakerDetailPage
into the same module as SpeakerListPage
:
- Comment out all of
SpeakerDetailModule
.
- Add
SpeakerDetailPage
to the declarations
and entryComponents
of SpeakerListModule
.
- Add a second parameter
[SpeakerDetailPage]
to theforChild()
call in SpeakerListModule
.
- Hack up
IonicPageModule
in node_modules/ionic-angular/index.js
to add this parameter:
IonicPageModule.forChild = function (page, addlPages) {
return {
ngModule: IonicPageModule,
providers: [
{ provide: /** @type {?} */ (LAZY_LOADED_TOKEN), useValue: page },
{ provide: 'hackeroo-addpages', useValue: addlPages},
{ provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: page, multi: true },
]
};
- and hack up
ModuleLoader.prototype.load
in util/module-loader.js
to receive it:
var /** @type {?} */ ref = loadedModule.create(_this._injector);
var /** @type {?} */ component = ref.injector.get(LAZY_LOADED_TOKEN);
_this._cfrMap.set(component, ref.componentFactoryResolver);
var addlPages = ref.injector.get('hackeroo-addpages');
if (addlPages) {
var ncomps = addlPages.length;
var i;
for (i = 0; i < ncomps; i++) {
_this._cfrMap.set(addlPages[i], ref.componentFactoryResolver);
}
}
- Finally, change the way
SpeakerDetailsPage
is pushed in SpeakerListPage
from a string to the actual SpeakerDetailsPage
class/constructor.
Have not tested what happens with providers yet, but perhaps somebody will find it interesting.