0.0.2 • Published 8 years ago

simple-spa-router v0.0.2

Weekly downloads
5
License
ISC
Repository
github
Last release
8 years ago

Router

A router for SAP project, depend on jquery.

Use

    router.config(function(state){
        state
            .when('hello', {
                templateUrl: 'tpl/hello.html',
                cb: function(state){
                    //state: current router name
                    console.log(state) 
                    //'hello'
                }
            })
            .when('name', {
                templateUrl: 'tpl/name.html',
                cb: function(state){}
            })
            .when('go', {
                templateUrl: 'tpl/go.html',
                cb: function(state){}
            })
            .when('test', {
                template: '<h2>Test!</h2>',
                cb: function(state){}
            })
            .other('test');
    })

    //default: '#'
    router.setHashMode('#!');

    $('button').on('click', function(){
        router.go('go');
    })

    //html
    <a state="hello">hello</a>

    //Show the view
    <RouterView></RouterView>