skylark-router
An elaborate front-end routing framework.
Features
- Support Hashbang, HTML5 pushstate, internal implementation three routing mode, the routing mode can be set by attributes or automatically by the framework, without affecting the implementation of the application.
- Supports global events to implement hooker functions.
- Lightweight, even if allinone is only 13k(minified),5k(gzip)
Dependences
Project | Status | Description |
---|---|---|
skylark-langx | v0.9.1 | Javascript language extension library |
Different builds
build | Description | |
---|---|---|
full | skylark-router-all.js | included skylark-langx |
only router | skylark-router.js | not included skylark-langx |
full (development) | uncompressed/skylark-router-all.js | included skylark-langx |
only router (development) | uncompressed/skylark-router.js | not included skylark-langx |
Installation
There are multiple ways to install the skylark-router library.
- cdn
http://registry.skylarkjs.org/packages/skylark-router/v0.9.2/skylark-router-all.js or
http://registry.skylarkjs.org/packages/skylark-router/v0.9.2/uncompressed/skylark-router-all.js - npm
npm install skylark-router --save - bower
bower install skylark-router
Usage
Refence router module object.
- Using the skylark-router library for a AMD module.
;
- Using the skylark-router library for a global object named skylarkjs.
<script type="text/javascript" src="http://registry.skylarkjs.org/packages/skylark-router/v0.9.2/skylark-router-all.js"></script><script> // skylarkjs.router.route(path,setting);</script>
- Using the skylark-router library for a AMD package.
;
Add route defines.
var homeRoute = router; var pageRoute = router;
add callback function for route.
When the route is changed, the following event are triggered in order.
- exiting (for previous route)
- entering (for new route)
- entered (for new route)
- exited (for previous route)
In adding route at the same time, you can add the same name of the callback function, after the route is added,you can also add callback function for these events.
homeRoute; pageRoute;
Start router.
srouterstart;
Hooker
The router supports global events and you can implement hooker functions by listening to global events. Built-in global events have routing before current route change and routed after current route change.
router;
Select engine
The router support the following three routing engines.
- html5 history API egine
- hash egine
- internal management engine
The useHistoryApi attribute and useHashbang attribute of router object are used to control which engine is used:
- useHistoryApi === null && useHashbang===null (default)
The router automatically determine which engine to use, if running on the web, he html5 history API egine is used; if running in the local file system, The internal egine is used. - useHistoryApi === true
The html5 history API egine is used. - useHistoryApi !== true && useHashbang===true
The hash egine is used. - useHistoryApi === false && useHashbang===false
The internal management engine is used.
API Document
- baseUrl()
- current()
- go()
- map()
- off()
- on()
- one()
- path()
- previous()
- Route
- Route.prototype.match
- Route.prototype.path
- route()
- routes()
- start()
- trigger()
Examples
Please access the following site for the execution of each example program under the "/examples" directory.
Building skylark-router
- Ensure that Node.js is installed.
- Run npm gulp -g to ensure gulp is installed.
- Run npm install to ensure the required dependencies are installed.
- change current directory to build/, and run gulp. The builds will be placed in the dist/ directory.
Integration
This library is completely built-in on skylark-spa, and when you use skylark-spa or skylark.js to develop an application, you do not have to use this library's API directly
License
Released under the MIT