Skip to content

AOT with multiple root module #4624

Description

@hikalkan

OS?

Windows 10

Versions.

Node v6.9.1
Npm v3.10.8.
ng-cli beta.30

Repro steps.

In brief, I want to bootstap one of my root modules based on an async call to the server. So, my code is like that:

AppPreBootstrap.run(() => { 
    if (abp.session.userId) {
        AppPreBootstrap.bootstrap(AppModule);
    } else {
        AppPreBootstrap.bootstrap(AccountModule);
    }
});

//A workaround to make angular-cli finding the startup module!
var b = false; if (b) { platformBrowserDynamic().bootstrapModule(AppModule); }

Given workaround works fine when AOT is disabled. But, when AOT is enabled, it only compiles AppModule and the logic above can not work.

I know AOT statically analysis main.ts and bundles all module files starting from the root module. But I also believe my case is not so unique. I simple want to bootstrap a different module if user has not logged in.

So, isn't that possible or is there a way of doing it? If not, how do you recommend as a best practice? Should I merge 2 modules and implement the logic with routes and route guards?

Thanks.

Activity

  1. deebloo commented on Feb 11, 2017

    @deebloo
    Contributor

    @hikalkan I think best practice in this case would be to manage this with routes and router guards. You can also lazy load those modules from the router so only the code needed to run would be downloaded.

  2. hikalkan commented on Feb 11, 2017

    @hikalkan
    Author

    I will try the lazy load first to see if it's possible. Thank you @deebloo

  3. hikalkan commented on Feb 12, 2017

    @hikalkan
    Author

    I suppose there is no way of doing that.

  4. nekkon commented on Feb 13, 2017

    @nekkon

    need to be able to select module. Error is thrown with aot on

  5. deebloo commented on Feb 13, 2017

    @deebloo
    Contributor

    @hikalkan did you get things working with the router?

  6. hikalkan commented on Feb 13, 2017

    @hikalkan
    Author

    No. What I did is to create a new RootModule which lazy loads other modules via router.
    But I did not like that solution much :(

  7. deebloo commented on Feb 13, 2017

    @deebloo
    Contributor

    @hikalkan ok. that does sound closer to best practice for angular though.

  8. sohaibjaved44 commented on Feb 21, 2017

    @sohaibjaved44

    Hey I have followed this documentation : https://www.aspnetzero.com/Documents/Getting-Started-Angular
    things went really good as expected. But after successful login I'm unable to see dashboard, it redirects me back to login. I guess it is something related to routing?

  9. hikalkan commented on Feb 21, 2017

    @hikalkan
    Author

    I suppose here is not the best place to ask this question :) Can you write to the aspnetzero forum.

  10. sohaibjaved44 commented on Feb 22, 2017

    @sohaibjaved44

    How long it will take to get a response on forum against this topic? http://forum.aspnetboilerplate.com/viewtopic.php?f=5&t=5201

  11. filipesilva commented on Mar 9, 2017

    @filipesilva
    Contributor

    @hansl can you have a look?

  12. chrisnicola commented on Mar 28, 2017

    @chrisnicola

    Can anyone from the Angular team confirm the principle behind AoT not supporting multiple entry points?

    Is it a basic principle of Angular 2+ that there must only ever be one root module and everything has to be part of one monolithic SPA application with centralized routing?

    This feels like a distinct lack of flexibility that real world applications often require. In my mind AoT needs to just work, regardless of whether or not I have a single monolithic application, multiple sub application or I just want to drop in some components on a static marketing page that is optimized for SEO.

  13. miiihi commented on Nov 22, 2017

    @miiihi

    I've patched the AngularCompilerPlugin to allow for multiple entry points. Are you interested in a PR?

  14. 7 remaining items

  15. filipesilva commented on Oct 1, 2019

    @filipesilva
    Contributor

    Heya, is this still a problem? Can someone provide a repro using the current version of Angular CLI please?

  16. added this to the needsTriage milestone on Oct 1, 2019
  17. added
    featureLabel used to distinguish feature request from other issues
    and removed on May 21, 2020
  18. modified the milestones: needsTriage, Backlog on May 21, 2020
  19. angular-automatic-lock-bot commented on Dec 6, 2020

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  20. locked and limited conversation to collaborators on Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: @ngtools/webpackfeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions