@jace1995/routes
v2.0.0
Published
TypeScript helper for creating routes and links to them
Downloads
1
Readme
@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);