BRouter

1. Get the BDefer.js and the BRouter.js files:

BDefer.js (Right click and "Save link as...") BRouter.js (Right click and "Save link as...")

2. Include the files in your project:

<script type="text/javascript" src="BDefer.js"></script>
<script type="text/javascript" src="BRouter.js"></script>

3. Look at the Example Code ↓

                   	

    /* use case */
    
    function selectFromDatabase(table, id) {
        //...
    }

    var router = new Router();

    router.on(/dogs\/\d\d/, function (value, data) {
    
        selectFromDatabase(table, id);
        
    });

    router.on(/cats\/\d\d\d/, function (value, data) {
    
        selectFromDatabase(table, id);
        
    });

    router.on('click', function (value, data) {
    
        selectFromDatabase(table, id);
        
    });

    var router2 = new Router();

    router2.on({
    
        id : /page_\d/
        
    }, function (value, data) {
    
        selectFromDatabase(table, id);
        
    });

    router2.on(router);

    router2.test('click');

    window.changeURL = function (e) {
    
        router.test(hash, e);
        
    };