1.1.5 • Published 3 years ago

ngx-route-maker v1.1.5

Weekly downloads
14
License
MIT
Repository
github
Last release
3 years ago

NgxRouteMaker

This library for generating routes

Install

$ npm install ngx-route-maker --save

Add package to NgModule imports:

import { NgxRouteMakerConfig, NgxRouteMakerModule } from 'ngx-route-maker';

const routesConfig: NgxRouteMakerConfig = {
  routes: {
    home: '/',
    dashboard: '/dashboard',
    pages: {
      _path: 'pages',
      page: '/{slug}',
      anotherPage: '/another/{slug}'
    }
  }
};

@NgModule({
  ...
  NgxRouteMakerModule.forRoot(routesConfig),
  ...
})

Usage

  • Usage with service:
import { NgxRouteMakerService } from 'ngx-route-maker';

export class DashboardComponent {

  constructor(
    private routeMaker: NgxRouteMakerService
  ) {
  }

  public getUrlByString(): string {
    return this.routeMaker.make('pages.page', { slug: 'new-page' });
  }

  public getUrlByArray(): string {
    return this.routeMaker.make(['pages', 'page'], { slug: 'new-page' });
  }

}

Usage with service

  • From string: /pages/new-page

this.routeMaker.make('pages.page', { slug: 'new-page' });
  • From array: /pages/new-page

this.routeMaker.make(['pages', 'page'], { slug: 'new-page' });
  • With default route for empty result: /home

this.routeMaker.make('fake.path', {}, '/home');

otherwise, you'll get an error for non-existent route

Usage with pipe:

  • From string: /pages/new-page
<a [routerLink]="'pages.page' | makeRoute: { slug: 'new-page' }">My Link</a>
  • From array: /pages/new-page
<a [routerLink]="['pages', 'page'] | makeRoute: { slug: 'new-page' }">My Link</a>
  • With default route for empty result: /home
<a [routerLink]="'pages.page' | makeRoute: { slug: 'new-page' } : '/home'">My Link</a>

####NgxRouteMakerConfig

KeyValue
routesNgxRouteMaker

####NgxRouteMaker | Key | Value | | --- | --- | | _path | that's prefix which will be applied for each inside route in the same depth | | key: string | string or NgxRouteMaker |

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago