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

2.1.6 • Public • Published

Goodrouter, TypeScript edition

Check out our website, the documentation. And feel free to join our Discord server!

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");
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.1.6
    197
    • latest

Version History

Package Sidebar

Install

npm i goodrouter

Weekly Downloads

356

Version

2.1.6

License

ISC

Unpacked Size

110 kB

Total Files

22

Last publish

Collaborators

  • elmerbulthuis