Skip to content

Router: Enable loadChildren to support a function that returns a Promise #9938

Closed

Description

@brandonroberts

I'm submitting a ... (check one with "x")

[ ] bug report
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

The loadChildren route config property only accepts a string

Expected/desired behavior

The loadChildren route config property accepts a string or function that returns a promise

Reproduction of the problem
If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).

What is the expected behavior?

What is the motivation / use case for changing the behavior?

In order to allow lazy loading in Webpack 1 with the upcoming @AppModules, there needs to be a way to return a promise that resolves an app module.

const routes: Routes = [
  {
    path: 'parent',
    loadChildren: () => new Promise(resolve => {
      require.ensure([], require => {
        resolve(require('./parent/module').ParentAppModule);
      })
    })
  }
];

It would also be helpful if this support were added to the SystemJsAppModuleLoader so SystemJS and Webpack are supported out of the box.

Please tell us about your environment:

  • Angular version: 2.0.0-rc.X
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5 | Dart]

cc: @vsavkin @tbosch

Activity

  1. brandonroberts commented on Jul 12, 2016

    @brandonroberts
    ContributorAuthor

    Tested and working with a custom app module loader using a function instead of a string with no changes needed.

  2. matt-psaltis commented on Aug 10, 2016

    @matt-psaltis

    Hi @brandonroberts do you have an example of this working in a plnkr or github repo that's compatible with router v3 rc1?

  3. brandonroberts commented on Aug 10, 2016

    @brandonroberts
    ContributorAuthor

    I have an example gist here of using a custom loader: https://gist.github.com/brandonroberts/02cc07face25886fe142c4dbd8da1340

  4. angular-automatic-lock-bot commented on Sep 9, 2019

    @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.

  5. locked and limited conversation to collaborators on Sep 9, 2019
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions