{"id":20513962,"url":"https://github.com/webreflection/a-route","last_synced_at":"2025-04-14T00:04:20.264Z","repository":{"id":57171595,"uuid":"216751805","full_name":"WebReflection/a-route","owner":"WebReflection","description":"Express like routing as Custom Element or standalone","archived":false,"fork":false,"pushed_at":"2020-09-16T12:15:59.000Z","size":41,"stargazers_count":54,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-31T15:58:17.618Z","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":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebReflection.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-22T07:37:22.000Z","updated_at":"2024-12-16T14:00:48.000Z","dependencies_parsed_at":"2022-08-24T14:42:25.015Z","dependency_job_id":null,"html_url":"https://github.com/WebReflection/a-route","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fa-route","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fa-route/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fa-route/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fa-route/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/a-route/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233828146,"owners_count":18736578,"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-11-15T21:14:04.342Z","updated_at":"2025-01-14T00:54:26.489Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","readme":"# a-route\n\n\u003csup\u003e**Social Media Photo by [Jakub Gorajek](https://unsplash.com/@cinegeek) on [Unsplash](https://unsplash.com/)**\u003c/sup\u003e\n\nExpress like routing, as Custom Element or standalone, inspired by [page.js](https://visionmedia.github.io/page.js/).\n\n\n### app API\n\n  * `app.get(path:string|RegExp, cb:Function[, cb2, ...]):app` to subscribe one or more callbacks for the specified route\n  * `app.delete(path:string|RegExp, cb:Function[, cb2, ...]):app` to unsubscribe one or more callbacks for the specified route\n  * `app.navigate(path:string[, operation:string = 'push']):void` to navigate to the first matching route for the given path. By default, it pushes to the history but it could `replace`, if the second parameter is the _replace_ string, or `ignore`.\n  * `app.param(path:string|RegExp):app` to subscribe to a specific parameter regardless of the route\n  * `app.use(path:string|RegExp):app` to subscribe a callback for a specific mount point or all of them\n\n\n### Example\n\nThe following is a basic example, also [available live](https://webreflection.github.io/a-route/test/?).\n\n```html\n\u003cscript src=\"//unpkg.com/a-route\"\u003e\u003c/script\u003e\n\n\u003c!-- simply add `is=\"a-route\"` to any link in your page --\u003e\n\u003ca is=\"a-route\" href=\"/test/?query=value\"\u003etest query\u003c/a\u003e\n\n\u003c!-- you can also add `no-propagation`, to stop propagation on click\n    or you could add `replace` to replace state instead of pushing it --\u003e\n\u003ca is=\"a-route\" href=\"/test/OK\" no-propagation replace\u003etest OK\u003c/a\u003e\n\n\u003c!-- unregistered routes will pass through `'*'` handler, if any --\u003e\n\u003ca is=\"a-route\" href=\"/whatever\"\u003etest 404\u003c/a\u003e\n```\n\n```js\n// import {app} from 'a-route';\n// const {app} = require('a-route');\nconst {app} = ARoute;\n\n// define routes\napp\n  .get('/test/?query=:query', function (ctx) {\n    console.log(ctx);\n    /*\n    {\n      \"path\": \"/test/?query=value\",\n      \"params\": {\n        \"query\": \"value\"\n      }\n    }\n    */\n  })\n  .get('/test/:status', function (ctx) {\n    console.log(ctx);\n    /*\n    {\n      \"path\": \"/test/OK\",\n      \"params\": {\n        \"status\": \"OK\"\n      }\n    }\n    */\n  });\n\n// intercept all unregistered calls\napp.get('*',\n  function (ctx, next) {\n    console.log(ctx);\n    /*\n    {\n      \"path\": \"/whatever\"\n    }\n    */\n    next();\n  },\n  // will receive the ctx object too\n  console.error\n);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fa-route","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreflection%2Fa-route","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fa-route/lists"}