goodrouter
TypeScript icon, indicating that this package has built-in type declarations

2.0.6 • Public • Published

Goodrouter, TypeScript edition

A good router should:

  • [x] work in a server or a client (or any other) environment
  • [x] be able to construct routes based on their name
  • [x] should have a simple API!
  • [x] not do the actual navigation!
  • [x] be framework agnostic
  • [x] be very minimal and simple!

Check out our (website)[https://www.goodrouter.org], the (documentation) [https://ts.goodrouter.org]. And feel free to join our (Discord server)[https://discord.gg/BJ8v7xTq8d]!

Example

const router = new Router();

router.insertRoute("all-products", "/product/all");
router.insertRoute("product-detail", "/product/{id}");

// And now we can parse routes!

{
  const [routeName] = router.parseRoute("/not-found");
  assert.equal(routeName, null);
}

{
  const [routeName] = router.parseRoute("/product/all");
  assert.equal(routeName, "all-products");
}

{
  const [routeName, routeParameters] = router.parseRoute("/product/1");
  assert.equal(routeName, "product-detail");
  assert.deepEqual(routeParameters, { id: "1" });
}

// And we can stringify routes

{
  const path = router.stringifyRoute("all-products");
  assert.equal(path, "/product/all");
}

{
  const path = router.stringifyRoute("product-detail", { id: "2" });
  assert.equal(path, "/product/2");
}

Install

npm i goodrouter

DownloadsWeekly Downloads

35

Version

2.0.6

License

ISC

Unpacked Size

123 kB

Total Files

66

Last publish

Collaborators

  • elmerbulthuis