1

I have tried Spinejs library for a few days, I have the document on Spinejs.com but till now, I still don't know how exactly Spine routing work. From the document, I know how to create a new route and add them to Spine routing. But how it work? I tried to create an example with 2 controller Task and TaskList extends from Spine.Controller, I also did add 2 routing controllers: "#/task" and "#/tasklist":

Spine.route.add("#/task");
Spine.route.add("#/tasklist");
Spine.route.setup();

in Task and TaskList controller, I simply alert an message in their constructor.

But when I browse: "http://hellospine.html/#task" -> nothing happen then "http://hellospine.html/#tasklist" -> nothing happen I thought that, the route values in url "#task" and "#tasklist" let spine call constructor of appropriate controller, but it's not working.

Do you have any idea ? Should I config anymore to make it run appropriate controller ? I also wanna know work flow of spine routing, please help me, thanks a lot!

UmbalaAZ
  • 165
  • 1
  • 1
  • 11

1 Answers1

3

3 things:

  1. Spine.Route.add is meant to be used out of controllers.
  2. route does not need #.
  3. You have to specify a callback function to execute when the route is reached

so:

Spine.Route.add('/hi', function () {
    alert('Hey you!');
});
Spine.Route.setup()

demo here

But please refer to http://spinejs.com/docs/routing

Cheers.

abernier
  • 27,030
  • 20
  • 83
  • 114