lit-router

0.2.2 • Public • Published

Lit-Router

This is a simple router that takes advantage of how tagged template literals work in ES6 to define route objects. It was inspired by seeing how lit-html works.

This router provides a function that will map from a URL (as a string) to a block of code and (in the opposite direction) a function that will map from a name to a URL.

It does not manage a browser's location or history objects.

Install

yarn add lit-router

Usage

import { defroute, routeTo, urlFor } from 'lit-router';
 
const routes = {
  index: [defroute`/users`, (context) => {}],
  show: [defroute`/users/${'id'}`, (context, params) => {}]
};
 
const context = {};
 
routeTo(context, routes, window.location.pathname);
 
urlFor(routes, 'show', { id: 5 });
// => '/users/5'

Tests

To run the tests in node run:

yarn test

To run them in a browser run:

yarn server

Package Sidebar

Install

npm i lit-router

Weekly Downloads

4

Version

0.2.2

License

MIT

Unpacked Size

7.71 kB

Total Files

8

Last publish

Collaborators

  • danston