AmpersandJS / ampersand-router

Clientside router with fallbacks for browsers that don't support pushState. Mostly lifted from Backbone.js.
MIT License
70 stars 16 forks source link

event binding fails while initialize new Router(options) #23

Closed ingoradatz closed 9 years ago

ingoradatz commented 10 years ago

When creating a new router, you may pass its routes hash directly as an option, if you choose.

The route init want to read particular callbacks from the surrogate object. if (!callback) callback = this[name];

Problem is that the surrogate object is created in the Router.extend() function only. When passing the routes hash directly this[name] is always undefined and the event binding is broken.

Can the extend step be included in the constructor?

latentflip commented 9 years ago

Hey, @llabball

Can you show me how you are trying to pass the routes in to the initialize? I'm not sure if this is a bug, or poor documentation.

Thanks!

ingoradatz commented 9 years ago

Hi @latentflip,

unfortunately i cannot find the broken code anymore but what i remember is that i have tried to give the routes as option in the init step of the router.

constructor / initialize new Router([options])

When creating a new router, you may pass its routes hash directly as an option, if you choose. All options will also be passed to your initialize function, if defined. http://ampersandjs.com/docs#ampersand-router-constructor-initialize

something like this

var router = new Router({
  "help/:page":         "help",
  "download/*path":     "download",
  "folder/:name":       "openFolder",
  "folder/:name-:mode": "openFolder"
})
lukekarrys commented 9 years ago

An old issue, but I thought I'd chime in. The code to pass routes when initializing is

var router = new Router({
  routes: {
    "help/:page":         "help",
    "download/*path":     "download",
    "folder/:name":       "openFolder",
    "folder/:name-:mode": "openFolder"
  }
})

I created #42 to clear up the documentation a bit and add a test for this for future regression purposes.

ingoradatz commented 9 years ago

:+1: