named-routes-angular
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Angular named routes

As a laravel developer i like to have named routes feature in angular too!

Install compiled version

npm install named-routes-angular --save

Import "NamedRoutesModule" in app.module.ts

...
import { NamedRoutesModule } from 'named-routes-angular';

@NgModule({
  imports: [
    ...
    NamedRoutesModule
  ],
  ...
})
export class AppModule {}
...

Define routes in app-routing.module.ts

...
const routes: Routes = [
  {
    path: 'hero',
    data: {
      name: 'hero'
    },
    children: [
      {
        path: '',
        component: HeroesComponent,
        data: {
          name: 'index'
        }
      },
      {
        path: ':id',
        children: [
          {
            path: 'show',
            component: HeroShowComponent,
            data: {
              name: 'show'
            }
          },
          {
            path: 'edit',
            component: HeroEditComponent,
            data: {
              name: 'edit'
            }
          }
        ]
      }
    ]
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}
...

Use it in view

...
<a [routerLink]="'hero.edit' | namedRoute: [hero.id]">{{ hero.name }}</a>
...

Readme

Keywords

none

Package Sidebar

Install

npm i named-routes-angular

Weekly Downloads

0

Version

1.0.2

License

none

Unpacked Size

104 kB

Total Files

26

Last publish

Collaborators

  • saeed_pooyanfar