ezy-routing v1.0.8
EZY ROUTING
Ezy routing is routing library for creating single page web applications.
How to Use?
Download
npm install ezy-routing --save-dev
Include
<script src="path/to/routing.min.js"></script>
Usage
<script>
EzyRouting.init({
pageNotFound:function(){
//Do Something here
},
routes:[
{url:'', action:function(){}},
{url:'about',action:function(){}}
]
});
</script
Options
pageNotFound*
Value - Function
Description: This function will be triggered when route doesn't match.
loader
Value - Function
Description: When route is changed in the URL this function will be triggered.
before
Value - Function
Description: After loader is initiated this function will be triggered and this function should return a PROMISE object. On success of promise object route action will be triggered
routes*
url*
Value - String
Description: Need to specify the route URL
Examples
- 'about'
- 'product/create'
- 'product/:id' - ':id' is dynamic value and it is mandatory
- 'product/:id?' - ':id' is dynamic value and it is optional. this url will match for 'product/' and 'product/123'
data
Value - Any value
Description: Pass some data from route object to the action during runtime. Example if you are using same action/function in multiple route to differentiate you can pass data.
action
Value - Function
Parameter - Object contains 'data' and 'params'. Here 'data' is data value passed from route and 'params' will have the dynamic value in the route URL
Route: {url:'product/:id', data:"Product View screen", action:....} Parameter for the URL 'product/123': {data:"Product View screen", params:{id:123}}
Description: Once route matches this function will be executed Note: If before is specified then promise object should get resolved to execute action
redirectTo
Value - String
Description: Need to specify the redirect URL of some other route. External Link redirect will not happen. Note: Either redirectTo or action is mandatory
children
Value - Array
Description: Need to specify the child routes in this field, which accepts array of routes
Note:
It is tested in Chrome and Firefox. Need to fix issues in Internet Explorer