https://github.com/qsctech/router.js
Router.js
https://github.com/qsctech/router.js
Last synced: about 1 year ago
JSON representation
Router.js
- Host: GitHub
- URL: https://github.com/qsctech/router.js
- Owner: QSCTech
- Archived: true
- Created: 2013-09-06T08:33:34.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-10-07T06:50:07.000Z (over 12 years ago)
- Last Synced: 2025-03-14T22:13:03.823Z (over 1 year ago)
- Language: CoffeeScript
- Homepage:
- Size: 121 KB
- Stars: 5
- Watchers: 36
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Router.js
类似 Backbone 的路由实现
## Usage
### 基本使用
```javascript
router = new Router;
// 方式一
route = {
route: "#!/book/:id",
callback: function(id) {console.log(id)},
context: this
}
router.add(route);
// 方式二
routes = {
"#!/book/:id": function(id) {console.log(id)},
"#!/shelf/:id": function(id) {console.log(id)}
}
router.add(routes);
// 方式三
routes = [
{
route: "#!/p:id",
callback: function(id) {console.log(id)},
context: this
},
{
route: "#!/img:id",
callback: function(id) {console.log(id)},
context: this
}
];
router.add(routes);
router.dispatch();
```
### 可选路由
```javascript
router = new Router;
route = {
route: "#!/books(/tag/:tag)(/shelf/:id)",
callback: function(tag, id) {
console.log({tag: tag, id: id});
}
};
router.add(route);
router.dispatch();
```
## License
Copyright (C) 2013 Hexcles Ma, Zeno Zeng
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.