https://github.com/candyframework/fast-regexp-router
快速正则路由
https://github.com/candyframework/fast-regexp-router
Last synced: 5 months ago
JSON representation
快速正则路由
- Host: GitHub
- URL: https://github.com/candyframework/fast-regexp-router
- Owner: candyframework
- Created: 2020-06-07T10:27:43.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-01-23T01:48:53.000Z (over 1 year ago)
- Last Synced: 2025-09-25T08:44:11.805Z (9 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Fast Router
## Principle
```typescript
route1 = '/'
route2 = '/user/{uid}'
route3 = '/posts/{id}'
// The system will process these routes into the following format
(?:\\/)|(?:\\/user\\/(\\w+))|(?:\\/posts\\/(\\w+))
```
## Usage
```typescript
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);
}
```