{"id":13565492,"url":"https://github.com/garygreen/lightrouter","last_synced_at":"2025-04-14T17:11:16.453Z","repository":{"id":18423721,"uuid":"21606076","full_name":"garygreen/lightrouter","owner":"garygreen","description":"Ultra lightweight javascript router","archived":false,"fork":false,"pushed_at":"2015-06-27T14:13:39.000Z","size":376,"stargazers_count":68,"open_issues_count":6,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T05:51:03.480Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/garygreen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-08T09:02:24.000Z","updated_at":"2024-08-09T20:05:49.000Z","dependencies_parsed_at":"2022-08-31T00:00:26.086Z","dependency_job_id":null,"html_url":"https://github.com/garygreen/lightrouter","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garygreen%2Flightrouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garygreen%2Flightrouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garygreen%2Flightrouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garygreen%2Flightrouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garygreen","download_url":"https://codeload.github.com/garygreen/lightrouter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923764,"owners_count":21183954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:01:48.337Z","updated_at":"2025-04-14T17:11:16.428Z","avatar_url":"https://github.com/garygreen.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"Lightrouter\n===========\n\n[![Build Status](https://api.travis-ci.org/garygreen/lightrouter.svg)](https://travis-ci.org/garygreen/lightrouter)\n\nUltra lightweight javascript router for those that need the most basic simple javascript routing.\n\n\n```javascript\n// Initialise the router\nvar router = new LightRouter({\n  type: 'path',             // Default routing type\n  handler: handler,         // Handler for string-based route callbacks\n  pathRoot: 'my-app/path',  // Base path for your app\n  routes: {\n     '':                           'home', // Base Url\n     'users':                      'userIndex',\n     'users/{id}':                 'userShow',\n     'users/(.*)':                 function(params) { /* User: params[0] */ },\n     'users/(?:create|{id}/edit)': function(params) { /* Create/Edit User: params.id */ }\n  }\n});\n\n// Route callback handlers\nvar handler = {\n  home:        function() { },\n  userIndex:   function() { },\n  userShow:    function(params) { /* Show user: params.id */ }\n};\n\n// Run the router\nrouter.run();\n```\n\n## Features\n\n* Super fast, regexes and objects are only initialized when they need to be.\n* Predictable and easy regex-based, no new syntax to learn.\n* Most routers use `:param` style syntax which interferes with regexes non-consuming match `(?:`\n* Node support\n* Support for matching from a base path (see `pathRoot`).\n* Traditional URL matching and support for hash based routing for single page apps.\n* Fully unit tested.\n\n#### Adding routes\n\nRoutes can be added with the `add()` method\n\n```javascript\nrouter.add(/anywhere-in-url-match\\/(\\w+)/, function(params) { });\nrouter.add('articles/{id}', function(params) { console.log('loading article ' + params.id); });\nrouter.add('user/{userId}/show', function(params) { console.log('showing user', params.userId); });\n```\n\n#### Routing Types\n\n Type   | Matches Against\n -------|----------------------------\n path   | window.location.pathname\n hash   | window.location.hash\n\n### Base/Path Root Support\n\nThe given `pathRoot` will be essentially stripped out when matching the routes:\n\n```javascript\n// Initialise the router\nvar router = new LightRouter({\n\ttype: 'path',\n\tpath: 'my-app-path/users/1',\n\tpathRoot: 'my-app-path',\n\troutes: {\n\t\t'users/{id}': function(params) { console.log('showing user', params.id); }\n\t}\n}).run();\n```\n\n\nAPI\n---\n\n### add([string|regex], callback)\nAdds 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.\n\n### empty()\nEmpty's all the routes\n\n### setType(['hash'|'path'])\nSet's the default routing type to either by hash or path\n\n### setPathRoot([string]url)\nSet's the paths root url (the paths root url will be removed when matching against routes).\n\n### setPath([string]path)\nSet's the path to match routes against (will default to window.location.pathname)\n\n### setHash([string]hash)\nSet's the hash to match routes against (will default to window.location.hash)\n\n### setContext([object]context)\nSet's the context to call matched routes under.\n\n### setHandler([object]handler)\nSet the object handler for string-based route callbacks.\n\n### getUrl([type])\nGet'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.)\n\n### match(route, [string|closure]callback)\nAttempt to match a one-time route.\n\n### run()\nChecks the routes against the url and calls the associated route function. Will also return the matched `Route` object.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarygreen%2Flightrouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarygreen%2Flightrouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarygreen%2Flightrouter/lists"}