Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
lightrouter
Advanced tools
Ultra lightweight javascript router for those that need the most basic simple javascript routing.
// Initialise the router
var router = new LightRouter({
type: 'path', // Default routing type
handler: handler, // Handler for string-based route callbacks
pathRoot: 'my-app/path', // Base path for your app
routes: {
'': 'home', // Base Url
'users': 'userIndex',
'users/{id}': 'userShow',
'users/(.*)': function(params) { /* User: params[0] */ },
'users/(?:create|{id}/edit)': function(params) { /* Create/Edit User: params.id */ }
}
});
// Route callback handlers
var handler = {
home: function() { },
userIndex: function() { },
userShow: function(params) { /* Show user: params.id */ }
};
// Run the router
router.run();
:param
style syntax which interferes with regexes non-consuming match (?:
pathRoot
).Routes can be added with the add()
method
router.add(/anywhere-in-url-match\/(\w+)/, function(params) { });
router.add('articles/{id}', function(params) { console.log('loading article ' + params.id); });
router.add('user/{userId}/show', function(params) { console.log('showing user', params.userId); });
Type | Matches Against |
---|---|
path | window.location.pathname |
hash | window.location.hash |
The given pathRoot
will be essentially stripped out when matching the routes:
// Initialise the router
var router = new LightRouter({
type: 'path',
path: 'my-app-path/users/1',
pathRoot: 'my-app-path',
routes: {
'users/{id}': function(params) { console.log('showing user', params.id); }
}
}).run();
Adds a route and calls the callback function if the routing url matches. Callback can be either a string (with use of the handler
option) or closure.
Empty's all the routes
Set's the default routing type to either by hash or path
Set's the paths root url (the paths root url will be removed when matching against routes).
Set's the path to match routes against (will default to window.location.pathname)
Set's the hash to match routes against (will default to window.location.hash)
Set's the context to call matched routes under.
Set the object handler for string-based route callbacks.
Get's the url to match routes against (will default to get the url on the default routing type as set in the options or by setType()
or for the type if supplied.)
Attempt to match a one-time route.
Checks the routes against the url and calls the associated route function. Will also return the matched Route
object.
FAQs
Lighweight javascript router
The npm package lightrouter receives a total of 74 weekly downloads. As such, lightrouter popularity was classified as not popular.
We found that lightrouter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.