mvcr

1.0.15 • Public • Published

mvcr

Zero-Dependency Client-Side Javascript Router

Description

This is a simple hash-based router that does path matching off of provided regular expressions.

Install

npm install mvcr

Usage

    import Router from 'mvcr'
 
    const router = new Router({
        routes: {
            default: {
                re: /(.*)/,
                handler: function (ctx) {
                    console.log(ctx)
                }
            }
        }
    })
 
    router.start()

See the example directory.

Handler

A handler for a given route is expected to be a function. At render time, this function will receive a context object containing a reference to the router instance and current route.

Example

    {
        router: {
            routes: {}
        },
        route: {
            path: '',
            query: {}
        }
    }

Route

The route object that's passed in the context will contain the current path, along with an object referencing any query string that was passed.

Dependencies (0)

    Dev Dependencies (10)

    Package Sidebar

    Install

    npm i mvcr

    Weekly Downloads

    1

    Version

    1.0.15

    License

    MIT

    Unpacked Size

    12 kB

    Total Files

    24

    Last publish

    Collaborators

    • wulfmann