# ngx-route-maker

> This library for generating routes

Latest version **1.1.5** (published 2021-05-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-route-maker
pnpm add ngx-route-maker
yarn add ngx-route-maker
bun add ngx-route-maker
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2021-05-13 |
| First published | 2020-02-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 127.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | cach |
| Keywords | angular, angular 2, angular router, angular make route, router |

## Links

- npm: https://www.npmjs.com/package/ngx-route-maker
- Repository: https://github.com/Cach/ngx-route-maker
- Issues: https://github.com/Cach/ngx-route-maker/issues
- npm.io page: https://npm.io/package/ngx-route-maker

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.9.0

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.1.5 (latest) — 2021-05-13
- 1.1.1 — 2020-07-31
- 1.1.0 — 2020-07-31
- 1.0.4 — 2020-02-04
- 1.0.3 — 2020-02-04
- 1.0.2 — 2020-02-04
- 1.0.1 — 2020-02-04
- 1.0.0 — 2020-02-04
- 0.0.1 — 2020-02-04

## README

# NgxRouteMaker

This library for generating routes

## Install

```bash
$ npm install ngx-route-maker --save
```

Add package to NgModule imports:

```typescript
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:

```typescript
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`
 
```typescript
this.routeMaker.make('pages.page', { slug: 'new-page' });
```

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

 - With default route for empty result: `/home`
 
```typescript
this.routeMaker.make('fake.path', {}, '/home');
```

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

## Usage with pipe:

 - From string: `/pages/new-page`

```html
<a [routerLink]="'pages.page' | makeRoute: { slug: 'new-page' }">My Link</a>
```
 - From array: `/pages/new-page`

```html
<a [routerLink]="['pages', 'page'] | makeRoute: { slug: 'new-page' }">My Link</a>
```

 - With default route for empty result: `/home`

```html
<a [routerLink]="'pages.page' | makeRoute: { slug: 'new-page' } : '/home'">My Link</a>
```

#### NgxRouteMakerConfig

| Key | Value |
| --- | --- |
| routes | NgxRouteMaker |

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

---
_Source: https://npm.io/package/ngx-route-maker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
