Backbone.js routes not firing
Posted
by
drale2k
on Stack Overflow
See other posts from Stack Overflow
or by drale2k
Published on 2012-03-21T22:22:04Z
Indexed on
2012/03/21
23:29 UTC
Read the original article
Hit count: 211
backbone.js
|coffeescript
I have a Base Router where i define some functions that need to be run everywhere. Every Router extends this Router.
Now my problem is, that none of my routes defined in this Base router, actually fire. Every other route in other Routers work fine. I have created a test route called 'a' which calls method 'b', which should fire an alert but nothing happens.
Here is the code: (This is Coffeescript, don't pay attention to the indentation, it's fine in my file)
class Etaxi.Routers.Base extends Backbone.Router
routes:
'register' : 'registerDevice'
'a' : 'b'
b: ->
alert "a"
initialize: ->
@registerDevice() unless localStorage.device_id?
@getGeolocation()
registerDevice: ->
@collection = new Etaxi.Collections.Devices()
@collection.fetch()
view = new Etaxi.Views.RegisterDevice(collection: @collection)
$('#wrapper').append(view.render().el)
getGeolocation: ->
navigator.geolocation.getCurrentPosition (position) ->
lat = position.coords.latitude
lng = position.coords.longitude
#$('#apphead').tap ->
# alert 'Position: ' + lat + " ," + lng
So when i visit '/register' or '/a' it should fire the appropriate method but it does not. I wonder if it has something to do with the fact that other Router extend from this Router? Would be wired but it is the only thing i can think of because every other Router works fine.
© Stack Overflow or respective owner