Skip to content

karaxuna/Router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Router - Simple javascript routing system

Example

Adding route and parsing:

var router = new Router();
router.addRoute('default', '/{controller}/{action}?{search}', function(o){ console.log(o); });
router.parse('/home/index?me=kaxa&shen=arvici');

Output:

{ 
    "controller":"home", 
    "action":"index", 
    "search":"me=kaxa&shen=arvici" 
}

Optional rooting parts:

router.addRoute('optional', '/{controller}/{action}[?{search}]', function(o){ console.log(o); });

Suceeds in both cases: '/home/index?me=kaxa&shen=arvici' and '/home/index'

In case if bypassed all routes:

var router = new Router({
    bypassedCallback: function(){
        console.log('Bypassed all routes');
    }
});

--

Default options

searchVariableName: 'search',
leftClosure: '{',
rightClosure: '}',
optionalLeftClosure: '[',
optionalRightClosure: ']',
bypassedCallback: function () { console.log('bypassed all rootes'); }

--

TODOs:

  1. Add functionality to option- searchVariableName (converts search part of url into object)
  2. Enable closures with multiple symbols

About

Simple javascript routing system

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages