Drazen
Drazen

Reputation: 2826

Backbone.js and navigation

Since backbone does not have its way of doing most things, i am confused on a lot of stuff. One of that things is the right way to navigate through my app.

I realize that a BB Router has a '.navigate' method which can be used to push urls and trigger routes. Now since my app has more than 1 router, i am not sure what the difference is between calling '.navigate' on the one or other router.

This are my Routers

new Etaxi.Routers.System()
new Etaxi.Routers.Header()
new Etaxi.Routers.Videos()
new Etaxi.Routers.News()

Now i could do

router = Etaxi.Routers.System()
// or i could do
router = Etaxi.Routers.Header()

router.navigate(url)

Is there any difference which router i use for my global app navigation? This seems weird to me.

Upvotes: 2

Views: 2906

Answers (1)

Derick Bailey
Derick Bailey

Reputation: 72888

There is no difference in which router you call. In fact, I recommend not calling a specific router, when you have multiple routers. Or, for that matter, don't bother calling a router at all. If you look at the source code for router's navigate method, you'll see that it does nothing more than pass through to Backbone.history.navigate. So just call that directly:

Backbone.history.navigate(url)

http://backbonejs.org/docs/backbone.html#section-114

I use multiple routers in nearly all of my apps, and this is how I call the navigate method. It works great, and avoids the confusion of which router to call.

Upvotes: 10

Related Questions