2.0.1 • Published 5 months ago

fast-regexp-router v2.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Fast Router

Principle

route1 = '/'
route2 = '/user/{uid}'
route3 = '/posts/{id}'

// The system will process these routes into the following format
(?:\\/)|(?:\\/user\\/(\\w+))|(?:\\/posts\\/(\\w+))

Usage

import FastRouter from 'fast-regexp-router'

const routesList = [
    {
        route: '/',
        handler: () => {
            console.log('index route requested')
        }
    },
    {
        route: '/user/{uid}',
        handler: (params) => {
            console.log('user requested, uid is: ' + params.uid);
        }
    },
    {
        route: '/posts/{id}',
        handler: (params) => {
            console.log('article requested, id is: ' + params.id);
        }
    }
];

const reg = new FastRouter();
// reg.setRoutes(routesList);
// Or
for(let v of routesList) {
    reg.setRoute(v);
}

const match = reg.exec('/user/123');
if(match) {
    match.handler(match.parameters);
}
2.0.1

5 months ago

2.0.0

7 months ago

1.1.3

2 years ago

1.1.2

3 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago