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

Feature: "ng generate component" needs a flag to generate routes for standalone components #27201

Open
stephenwithav opened this issue Mar 5, 2024 · 3 comments
Labels
area: schematics/angular target: feature This PR is targeted for a feature branch (outside of main and semver branches)

Comments

@stephenwithav
Copy link

stephenwithav commented Mar 5, 2024

Command

generate

Description

Running ng generate component users --standalone generates users/users.component.{css,html,spec.ts,ts} files.

For imported or lazy-loaded routes, we can create a users/users.routes.ts that looks like this:

import { Routes } from '@angular/router';
import { UserListComponent, UserDetailsComponent, CreateUserComponent, EditUserComponent } from './users/users.component';

export const routes: Routes = [
    { path: 'list', component: UserListComponent },
    { path: 'details/:id', component: UserDetailsComponent },
    { path: 'create', component: CreateUserComponent },
    { path: 'edit', component: EditUserComponent },
];

...and import it with loadChildren in app.routes.ts, but ng could simplify the process.

Describe the solution you'd like

ng generate component users --standalone --routes could scaffold the users/users.routes.ts file for us, letting us just fill it in as we go.

import { Routes } from '@angular/router';
import * from './users.component';

export const routes: Routes = [
    { path: '', component: UsersComponent },
];

An alternative is ng generate component users --standalone --routes=crud, which generates components and route mappings for each CRUD component. ng generate component users --standalone --routes=cr would only generates Create and Read components and mappings.

Describe alternatives you've considered

yasnippets with emacs, but ng incorporating this functionality would make life easier.

@alan-agius4 alan-agius4 added area: schematics/angular target: feature This PR is targeted for a feature branch (outside of main and semver branches) labels Mar 5, 2024
@alan-agius4 alan-agius4 changed the title Feature: "ng generate component" needs a flag to generate routes for standalone components. Feature: "ng generate component" needs a flag to generate routes for standalone components Mar 5, 2024
@stephenwithav
Copy link
Author

@alan-agius4 Would you like me to take a shot at adding this functionality?

@alan-agius4
Copy link
Collaborator

This is actually something that @AndrewKushnir was looking at sometime ago. We still had some pending design decisions, which required broader discussions with the rest of team.

@stephenwithav
Copy link
Author

Thank you for the info. I'll implement a placeholder in elisp for now.

@AndrewKushnir, I'm here to help if you want when those design decisions are made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: schematics/angular target: feature This PR is targeted for a feature branch (outside of main and semver branches)
Projects
None yet
Development

No branches or pull requests

2 participants