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.
GNU General Public License v2.0
402 stars 69 forks source link

Can we initialize a empty router #55

Closed satyasuman closed 12 years ago

satyasuman commented 12 years ago

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

azicchetti commented 12 years ago

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