@teddytags/router
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@teddytags/router

Efficient routing for TeddyTags.

Note to developers

This is an ultra-simple implementation of a router so don't expect it to work like a pro. But it will suffice most of your needs anyways.

Usage

const routes = [
  {
    //path to match
    path: "/",
    //Title of the page
    title: "Home",
    //component to render
    render: () => <Home />,
  },
  {
    path: "404",
    title: "404",
    render: () => <fourOhFour />,
  },
  {
    //the :foo is a parameter sliced from url
    path: "products/:foo",
    title: "Products",
    //use it here
    render: (p) => <Product name={p.foo} />,
  },
  {
    //the :endOfPath is a special parameter that matches till end of URL
    path: "blog/:endOfPath",
    title: "Blog",
    //use it here
    render: async (p) => {
      const fetcher = await fetch(`myblog.site/${p.endOfPath}.md`);
      const blogMD = await fetcher.text();
      return <Blog content={blogMD} />;
    },
  },
];

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    1

Package Sidebar

Install

npm i @teddytags/router

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

30.6 kB

Total Files

10

Last publish

Collaborators

  • obnoxiousnerd