{"id":21177432,"url":"https://github.com/betsol/js-router","last_synced_at":"2025-03-14T18:29:06.114Z","repository":{"id":15992537,"uuid":"18735727","full_name":"betsol/js-router","owner":"betsol","description":"Defining routes and generating URLs with JavaScript","archived":false,"fork":false,"pushed_at":"2016-01-22T14:50:14.000Z","size":148,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-20T19:07:35.056Z","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/betsol.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","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-04-13T17:57:42.000Z","updated_at":"2014-04-17T17:23:55.000Z","dependencies_parsed_at":"2022-08-30T11:10:36.577Z","dependency_job_id":null,"html_url":"https://github.com/betsol/js-router","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Fjs-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Fjs-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Fjs-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Fjs-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/betsol","download_url":"https://codeload.github.com/betsol/js-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243624796,"owners_count":20321165,"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-20T17:16:03.043Z","updated_at":"2025-03-14T18:29:06.082Z","avatar_url":"https://github.com/betsol.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"You can use this library to define routes and generate URLs in your JavaScript environment be it NodeJS or web browser.\n\nThis library is *AngularJS*, *CommonJS* and *AMD* compatible.\n\n# Installation\n\n## Using bower\n\n`bower install --save-dev betsol-js-router`\n\n# Usage\n\n## 1. Instantiate a routing service\n\n### NodeJS\n\n``` javascript\nvar RoutingService = require('js-router.js');\nvar routingService = new RoutingService();\n```\n\n### Browser\n\nIn browser environment `RoutingService` is registered globally with your `window` object.\n\n``` html\n\u003cscript type=\"text/javascript\" src=\"router.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n    var routingService = new RoutingService();\n\u003c/script\u003e\n```\n\n### AngularJS\n\n``` javascript\nangular.module('myModule', ['ng', 'ngRoutingService'])\n    .controller('AppCtrl', function(routingService) {\n        // Use \"routingService\" instance.\n    })\n;\n```\n\n## 2. Specify routes configuration\n\n``` javascript\nroutingService\n    .add('home', {\n        path: '/home'\n    })\n    .add('user', {\n        path: '/user/{userId}'\n    })\n    .add('user.service', {\n        path: '/user/{userId}/service/{serviceId}'\n    })\n    .add('spaces', {\n        path: '/spaces/{ spaces }'\n    })\n;\n```\n\n## 3. Generate some routes\n\n``` javascript\n// '/home' =\u003e '/home'\nroutingService.generate('home');\n\n// '/user/{userId}' =\u003e '/user/117'\nroutingService.generate('user', {\n    userId: 117\n});\n\n// '/user/{userId}' =\u003e '/user/1'\nroutingService.generate('user', {\n    userId: true\n});\n\n// '/user/{userId}' =\u003e '/user/0'\nroutingService.generate('user', {\n    userId: false\n});\n\n// '/user/{userId}' =\u003e '/user/'\nroutingService.generate('user', {\n    userId: null\n});\n\n// '/user/{userId}/service/{serviceId}' =\u003e '/user/117/service/33'\nroutingService.generate('user.service', {\n    userId: 117,\n    serviceId: 33\n});\n\n// '/spaces/{ spaces }' =\u003e '/spaces/spaces'\nroutingService.generate('spaces', {\n    spaces: 'spaces'\n});\n```\n\n# Configuration\n\n## Placeholder format\n\nIt's possible to use different placeholder formats for your routes definitions.\n\nConsider this paths:\n\n- /foo/:fooId/bar/:barId/baz\n- /foo/{fooId}/bar/{barId}/baz\n\nFirst path is using [AngularJS style placeholders][angular-routing], i.e. `:placeholder`\nand the second one is using [Symfony style placeholders][symfony-routing]: `{placeholder}`.\n\nRouting service needs to now what placeholder format you are going to use in order to\ncorrectly parse paths and generate URLs. You can specify format by using public method\n`setPlaceholderPattern`.\n\n**Example:**\n\n``` javascript\nvar routingService = new RoutingService()\n    .setPlaceholderPattern('symfony')\n    .add('foo-bar-baz', {\n        path: '/foo/{fooId}/bar/{barId}/baz'\n    })\n;\n\nvar url = routingService.generate('foo-bar-baz', {\n    fooId: 100,\n    barId: 500\n});\n\n// url == \"/foo/100/bar/500/baz\"\n```\n\nThe are two built-in placeholder formats:\n\n- \"angular\" (AngularJS or Ruby on Rails style)\n- \"symfony\" (Symfony framework style)\n\nIt's also possible to specify arbitrary placeholder format by providing part of\nregular expression used both for parsing paths and generating URLs.\n\n**Example:**\n\n``` javascript\nvar routingService = new RoutingService()\n    .setPlaceholderPattern('(%s)') // Django-style placeholder.\n    .add('foo-bar-baz', {\n        path: '/foo/(fooId)/bar/(barId)/baz'\n    })\n;\n```\n\n`%s` will be replaced with placeholder name during pattern matching.\n\n# Changelog\n\n[Changelog is here][changelog].\n\n# License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014 Slava Fomin II\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n[angular-routing]: http://docs.angularjs.org/api/ngRoute/provider/$routeProvider\n[symfony-routing]: http://symfony.com/doc/current/book/routing.html\n[changelog]: https://github.com/betsol/js-router/blob/master/changelog.md","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetsol%2Fjs-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbetsol%2Fjs-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetsol%2Fjs-router/lists"}