Reputation: 36940
I have a basic Spine/coffeescript app and I am trying to get the parameters out of the route that I have set up, by looking at examples of other applications. Here is the basic stack:
class Main extends Spine.Stack
el: "#main"
controllers:
sources: Sources
default: 'sources'
routes:
'/sources/:id': 'sources'
Here is the sources controller:
class Sources extends Spine.Controller
el: '#something'
constructor: ->
super
active: (params) ->
super
@id = params.id
@refresh()
@render()
However, params
is undefined when active is called. I am navigating to /#/sources/soemthing
. Maybe there is something about the sugar in the stack that I don't understand, but the example I've seen seems to just work in this way. Can anyone tell me what is missing?
Upvotes: 0
Views: 508
Reputation: 36940
So apparently the stack always initializes the default controller with no parameters before switching to one of the other controllers, even if you navigate to /#/route/parameter directly. After adding a default controller that does nothing, this problem went away.
class Main extends Spine.Stack
el: "#main"
controllers:
home: Home
sources: Sources
default: 'home'
routes:
'/': 'home'
'/sources/:zooniverse_id': 'sources'
P.S. If you are trying to get Spine help on SO, don't. Go to the SpineJS google group: https://groups.google.com/forum/#!forum/spinejs
Upvotes: 2