Skip to content

kuchun/make-route-path

 
 

Repository files navigation

NPM JavaScript Style Guide Badges Badges Badges Badges Badges Badges

Make route path

Make your router paths type safe and great!

npm install make-route-path --save
yard add make-route-path
const productUrl = makeRoutePath<
  {
    productId: number;
    fromSection: string;
    productSection: 'images' | 'description';
  },
  {
    someQueryParam?: string;
    someAnotherQueryParam?: string;
  }
>('/catalog/:productId/:fromSection/:productSection');

// Make url with params
productUrl({ productId: '10', fromSection: 'a123', productSection: 'images' });
// '/catalog/10/a123/images'

// Make url with query params
productUrl({
    productId: '10',
    fromSection: 'a123',
    productSection: 'images'
}, {
    someQueryParam: "test";
    someAnotherQueryParam: "test";
});
// '/catalog/10/a123/images?someQueryParam=test&someAnotherQueryParam=test'

// Returns real path
productUrl.PATH;
// '/catalog/:productId/:fromSection/:productSection'
//  usable for example react-router routes

About

🧁 Make route paths sweet again! Type safe route paths for your lovely router

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 97.2%
  • JavaScript 2.8%