Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for default exports in loadChildren and loadComponent callbacks #46323

Closed
markostanimirovic opened this issue Jun 9, 2022 · 5 comments
Assignees
Labels
area: router feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Milestone

Comments

@markostanimirovic
Copy link
Contributor

markostanimirovic commented Jun 9, 2022

Which @angular/* package(s) are relevant/related to the feature request?

router

Description

Support for default ES module exports will reduce repetitive code in routes config.

// app.routes.ts
export const appRoutes: Routes = [
  {
    path: '',
-   loadComponent: () => import('./home/home.component').then((m) => m.HomeComponent),
+   loadComponent: () => import('./home/home.component'),
  },
  {
    path: 'books',
-   loadChildren: () => import('./books/books.module').then((m) => m.BooksModule),
+   loadChildren: () => import('./books/books.module'),
  },
  {
    path: 'authors',
-   loadChildren: () => import('./authors/authors.routes').then((m) => m.authorsRoutes),
+   loadChildren: () => import('./authors/authors.routes'),
  }
];

// home.component.ts
@Component({ /* ... */ })
-export class HomeComponent {}
+export default class HomeComponent {}

// books.module.ts
@NgModule({ /* ... */ })
-export class BooksModule {}
+export default class BooksModule {}

Proposed solution

This feature will not introduce breaking changes, which means that we'll still be able to use .then((esModule) => esModule.exportedMember). Also, there will be a compilation error if an imported module does not have a default export.

I will create the PR for this feature if the feature request is accepted. 🙂

Alternatives considered

Using then((esModule) => esModule.ngModuleOrRoutesOrComponent) for each lazy loaded module, component, or routes.

@atscott atscott added feature Issue that requests a new feature area: router labels Jun 9, 2022
@ngbot ngbot bot modified the milestone: Backlog Jun 9, 2022
@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Jun 10, 2022

Additional context: this question was included into the Standalone APIs RFC and the decision was to avoid adding this for now due to a mixed signal from the community, see #45554 (comment):

Incorporating this feedback in our design, we do not intend to add default imports unwrapping to the router's 
loadComponent and loadChildren functions - we got mixed signals from the community and at the moment 
we prefer to stick to more verbose but clear and explicit API. We plan to revisit the advantages and 
disadvantages of default exports outside the context of standalone.

@markostanimirovic
Copy link
Contributor Author

Thanks @AndrewKushnir.

I've updated the description to avoid potential confusion about this feature:

This feature will not introduce breaking changes, which means that we'll still be able to use .then((esModule) => esModule.exportedMember). Also, there will be a compilation error if an imported module does not have a default export.

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Jun 10, 2022
@angular-robot
Copy link
Contributor

angular-robot bot commented Jun 10, 2022

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added feature: under consideration Feature request for which voting has completed and the request is now under consideration and removed feature: votes required Feature request which is currently still in the voting phase labels Jun 16, 2022
@alxhub alxhub self-assigned this Sep 28, 2022
@misha98857
Copy link

misha98857 commented Nov 19, 2022

This feature already implemented in PR #47586

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: router feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

5 participants