pillarjs / routington Goto Github PK
View Code? Open in Web Editor NEWTrie-based URL Routing
License: MIT License
Trie-based URL Routing
License: MIT License
Hi Is there a way to remove a defined route ?
I am creating a dynamic router based on top of routington, and as a way I need to add and remove routes. Is there a way to do this in routington ?
@jonathanong is there a way to detect the router finished without fining a match?
I want to be able to run a regex on the path from root level only after the router didn't already find a match.
Can we get an example on how the parse method can be used?
I can seem to find anywhere it is explicitly used.
Thanks
figure out how we want to handle it
each variable should have at least one digit
@jonathanong you have been identified as the last / most active committer in this repo which is inactive for a while. This ping is to check with you to determine:
thanks
Currently /path/:restofroute(.*) - does not match /path/abc/def/ghi/jkl/mnop
Is this not supported, or is there an alternate way of doing this?
right now, you have to use regular expressions
I have the following snippet and trying to patch a simple query string but for some reason it's not able to match it.
import routington from "routington";
class Router {
#router: routington
constructor() {
this.#router = routington();
}
get(path: string, method: string, ...cb: Array<Function>) {
const node = this.#router.define(path)[0];
node[method] = node[method] || []
node[method].push(...cb)
}
post(path: string, method: string, ...cb: Array<Function>) {
const node = this.#router.define(path)[0];
node[method] = node[method] || []
node[method].push(...cb)
}
match(path: string) {
return this.#router.match(path);
}
}
const router = new Router();
router.get('/name', 'GET', function (ctx: object, next: Function) { console.log('middleware') }, function (ctx: object) { console.log('handler') });
router.post('/name', 'POST', function (ctx: object) { console.log('handler2') });
// dispatch
function dispatcher(request: { path: string; method: string }): { param: string; handler: Function } | string | never {
const match = router.match(request.path);
if (!match) { console.log('404 - Not Found'); return "" };
const node = match.node;
const cb = node[request.method]
return {
param: match.param,
handler: cb
}
}
console.log(dispatcher({ path: '/name?age=50', method: 'GET' }));
Please assist.
Thanks
so you can literally build a router on top of this
When implementing an event based system it might be very helpful to know which rule matched, so we need a tag.
router.define('/page/:id(\\w{3,30})', { tag: 'page' })
router.define('/user/:id(\\w{3,30})', { tag: 'user' })
var match = router.match('/page/taylorswift')
console.log(match.tag); // output 'page'
https://www.npmjs.org/package/trie-router
apparently it's not taken. @pillarjs/owners
Currently I cannot register a wildcard in routington.
Example
router.define('*');
Or
router.define('/*');
Any help will be appreciated.
Hi,
Consider this example:
const routington = require("routington")
const router = routington();
router.define("/");
router.define("/name/:id");
router.define("name/:id/create");
var match = router.match("/name/anurag");
console.log(match);
How do I know against which route to the match object is created.
That is if there is a match, I wanted to know match.pattern should give me :
/name/:id
Is it possible currently, or can this feature be added.
In my code I have to define some rules on pattern, but I want the url pattern which has allowed this match, so those rules can be applied to the request before processing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.