dsroute
v1.0.2
Published
Discus Route. Route system for SPA (Single Page Applications)
Downloads
3
Maintainers
Readme
dsRoute - Discus Route
Route system for SPA (Single Page Applications)
Use less data traffic and make your application faster
- Resources:
- Lazy loading templates using ajax
- Optional cache for loaded templates
- Define a default route and error code routes
- Dependencies:
Example
index.html
!DOCTYPE html>
<html>
<head>
<title>dsRoute Example</title>
<meta charset="UTF-8">
</head>
<body>
<div>
<h1>Base application</h1>
</div>
<div id="content"></div>
</body>
<script src="signals.min.js"></script>
<script src="crossroads.min.js"></script>
<script src="hasher.min.js"></script>
<script src="jquery.min.js"></script>
<script src="dsRoute.js"></script>
<script src="app.js"></script>
</html>
app.js
fooController = function(id){
console.log('load view foo');
};
barController = function(id, slug){
console.log('load view bar with parameters', id, slug);
dsRoute.setRoutes({
//index route
'' : {templateUrl : 'home.html', controller : fooController},
//Route no cached template
'foo' : {templateUrl : 'foo.html', controller : fooController, nocache : true},
//Route with parameter and optional parameter
'bar/{id}/:slug:' : {templateUrl : 'bar.html', controller : barController},
//Route called when get 404 code error. You can use others code errors.
'404' : {templateUrl : '404.html', controller : fooController},
//Called when no route matched
'default' : {templateUrl : 'default.html', controller : fooController}
});
The template by default are showed on element #content. If you need to change the default element use:
dsRoute.setElRouteView('#maincontent');
Install
via npm
npm install dsroute --save
via bower
bower install dsroute --save
License
Copyright © 2017 Discus Tecnologia
Released under the MIT license.