Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

chialab/router-js

Repository files navigation

Router • A simple agnostic Router for Web Apps.

Documentation link Source link Authors link NPM License


Install

$ npm install @chialab/router
# or
$ yarn add @chialab/router

Use via cdn:

<script type="text/javascript" src="https://unpkg.com/@chialab/router-js"></script>

Example

import Router from '@chialab/router';

const appRouter = new Router();
appRouter.on('/user/:username', function(id) {
    fetchUserById(id);
});
appRouter.on('/posts/:id', function(id) {
    fetchPostById(id);
});
appRouter.on('/posts', function() {
    listPosts();
});
appRouter.on('*', function() {
    page404();
});
appRouter.start();

Development

Build status codecov

Requirements

In order to build and test Router, the following requirements are needed:

Build the project

Install the dependencies and run the build script:

$ yarn install
$ yarn build

This will generate the UMD and ESM bundles in the dist folder, as well as the declaration file.

Test the project

Run the test script:

$ yarn test

License

Router is released under the MIT license.