azicchetti / jquerymobile-router

A router/controller for jquery mobile. Also adds support for client-side parameters in the hash part of the url. The routes handles regexp based routes. This plugin can be used alone or (better) with Backbone.js or Spine.js, because it's originally meant to replace their router with something integrated with jQM.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can we initialize a empty router

satyasuman opened this issue · comments

Hi is it possible to initialize an empty router and then add routes to it?

Hi,
yes, you can setup an empty router, then add your routes at a later time.

Just invoke the add() method of the router instance:

myrouter.add({
        "#something": "bsHandler",
        "#otherone": { events: "s,h", handler: "bsHandler2" }
}, handlerObj);

The array syntax is also supported (and preferred):

myrouter.add([
        { "#something": "handler" },
        { "#otherone": { events: "s,h", handler: "handler2" } }
], handlerObj);

Cheers,
Andrea