@cubex/router
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

Cubex Router

Build Status npm version

import Router from '@cubex/router';

class Application {
    router: Router = new Router();

    constructor() {
        /*
         * Sets Default Route
         */
        this.router.setDefaultRoute(function () {
            console.log('Route: Default');
        });

        /*
         * Set Error Route
         */
        this.router.setErrorRoute(function () {
            console.log('Route: Default');
        });

        /*
         * Set Route and exit function
         */
        this.router.addRegex('test', function () {
            console.log('Route: Test');
        }, function(newHash: string) {
            console.log('Route Exit: Test, New Hash: ' + newHash);
        });

        /*
         * Set Route with parameter
         */
        this.router.addRegex('test/:id', function (id) {
            console.log('Route: Test, id: ' + id);
        });

        /*
         * Set Route with two parameters defined by function
         */
        this.router.addFunction('test', function (id, name) {
            console.log('Route: Test, id: ' + id + ', name: ' + name);
        });
    }

    /*
     * Start Router, with option to defer run until route change
     */
    start(defer: boolean = false) {
        this.router.start(defer);
    }

    /*
     * Stop Router
     */
    stop() {
        this.router.stop();
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @cubex/router

Weekly Downloads

1

Version

0.3.3

License

MIT

Unpacked Size

22.1 kB

Total Files

26

Last publish

Collaborators

  • sjohnsonaz