2.0.0 • Published 5 years ago

@jace1995/routes v2.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

@jace1995/routes

TypeScript helper for creating routes and links to them

Install

npm i -S @jace1995/routes

Usage

import { route } from '@jace1995/routes';

interface UserRoute {
  name: string;
}

function specialParamName(prop: string) {
  return `{${prop}}`;
}

const routes = {
  hello: route(() => `/hello`),
  user: route<UserRoute>(({ name }) => `/user/${name}`),
  special: route<UserRoute>(
    ({ name }) => `/special/${name}`,
    specialParamName
  ),
};

// /hello
console.log(routes.hello.path);

// /hello
console.log(routes.hello.url());

// /user/:name
console.log(routes.user.path);

// /user/noname
console.log(routes.user.url({ name: 'noname' }));

// /special/{name}
console.log(routes.special.path);