项目作者: danevans

项目描述 :
A simple router that takes advantage of how tagged template literals work in ES6
高级语言: JavaScript
项目地址: git://github.com/danevans/lit-router.git
创建时间: 2018-01-07T19:39:44Z
项目社区:https://github.com/danevans/lit-router

开源协议:

下载


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

  1. yarn add lit-router

Usage

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

Tests

To run the tests in node run:

  1. yarn test

To run them in a browser run:

  1. yarn server