Skip to content

Commit

Permalink
fix(compiler-cli): avoid handling functions in loadChildren as lazy l…
Browse files Browse the repository at this point in the history
…oad routes paths

The change avoids the compiler CLI internal API from mismatching the following case as lazy loading

```
import { NonLazyLoadedModule } from './non-lazy-loaded/non-lazy-loaded.module';

export function getNonLazyLoadedModule() { return NonLazyLoadedModule; }

export const routes = [
  { path: '/some-path', loadChildren: getNonLazyLoadedModule }
];
```

The output of the check is later passed to `RouteDef.fromString()`, so, it makes sense to be only a string.

Fixes angular/angular-cli#3204
  • Loading branch information
Meligy committed Dec 28, 2016
1 parent 6b02b80 commit 167b1e3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion modules/@angular/compiler-cli/src/ngtools_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function _collectRoutes(
*/
function _collectLoadChildren(routes: Route[]): string[] {
return routes.reduce((m, r) => {
if (r.loadChildren) {
if (r.loadChildren && typeof r.loadChildren === 'string') {
return m.concat(r.loadChildren);
} else if (Array.isArray(r)) {
return m.concat(_collectLoadChildren(r));
Expand Down

3 comments on commit 167b1e3

@maxime1992
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Meligy hi :)

I have something similar than that :
image

But when I use loadChildren with an exported function angular-cli tells me :

entry.split is not a function

Like in this issue : angular/angular-cli#3204
Except that here I'm not trying to lazy load the module.

Does your fix take the non lazy loaded case into account ? :)

@Meligy
Copy link
Owner Author

@Meligy Meligy commented on 167b1e3 Jan 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It's explicitly for that.

avoid handling functions in loadChildren as lazy load routes paths

The normal non-lazy-load function is being interpreted as a lazy-loading string. This PR ensures it's checked to be an actual string first. So that if it's a function, it doesn't get treated as a string, and it gets left alone to the router, which knows how to use it already in runtime.

@maxime1992
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I hope it'll be merged soon 😊!!

Please sign in to comment.