@ngspot/route-path-builder
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published


MIT commitizen PRs styled with prettier All Contributors spectator semantic-release

Declarative Route Path Management in Angular Apps

This library consists of a single abstract class: RoutePathBuilder. See this article to learn how to use it!

Features

  • ✅ < 3kb bundle size
  • ✅ A single source of truth for each path in the application
  • ✅ Strong typings
  • ✅ Access to Angular's dependency injection
  • ✅ Use of absolute links (meaning, the generated links are absolute)
  • ✅ Modularity
  • ✅ Use of property chaining to reflect the nested nature of the routes
  • ✅ Use of relative URL parts for the assembly of the URLs.
  • ✅ Flexible return type

Table of Contents

Installation

NPM

npm install @ngspot/route-path-builder --save

Yarn

yarn add @ngspot/route-path-builder

Usage

  1. Define your routes
// app-routes.ts
import { RoutePathBuilder } from '@ngspot/route-path-builder';

@Injectable({ providedIn: 'any' })
export class AppRoutes extends RoutePathBuilder {
  products = this.childRoutes('products', RoutesForProducts);

  about() {
    return this.url('about');
  }

  contact() {
    return this.url('contact');
  }
}

// routes-for-products.ts
@Injectable({ providedIn: 'any' })
export class RoutesForProducts extends RoutePathBuilder {
  orders() {
    return this.url('orders');
  }
}
  1. Use the AppRoutes:
class MyComponent {
  constructor(private appRoutes: AppRoutes) {}

  someMethod() {
    const aboutUrl = this.appRoutes.about().url;

    this.appRoutes.products.orders().navigate();
  }
}

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Dmitry A. Efimenko

📝 💻 🎨 📖

Ana Boca

📝

Also, thanks to Netanel Basal for inspiring me to come up with this solution.

This project follows the all-contributors specification. Contributions of any kind welcome!

Icons made by Freepik from www.flaticon.com

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.1
    27
    • latest
  • 2.0.0
    0
    • next

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.1
    27
  • 2.0.0
    0
  • 1.0.0
    4

Package Sidebar

Install

npm i @ngspot/route-path-builder

Weekly Downloads

31

Version

2.0.1

License

MIT

Unpacked Size

38 kB

Total Files

11

Last publish

Collaborators

  • dmitryefimenko