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