質問

Since Backbone's Router only work with "#", it means that it should be all in the same page. Should a BB application be only in one page and have only 1 Router?

役に立ちましたか?

解決

One of the many nice things about Backbone is that it is very unopinionated about how you work with it. For example, if you just want to use views, then you can do that, and if you want to just use models, you can do that as well.

A Backbone application can be a single-page application, and it certainly provides a lot of functionality to make that easier if that is your goal, but it doesn't have to be. There is absolutely nothing wrong with explicitly calling your views by hand instead of using a router.

To answer the second part of your question... No, you can have as many routers as you like. However, I'd say a large portion of Backbone apps out there make do with just one. I am working on a Backbone app that has over a hundred different views, and I've never run into an issue where I'd have to introduce a secondary router.

Finally, a bit of a correction on your end; The Router object actually doesn't enforce the "#" anymore as long as your browser has pushState functionality. Older browsers (mainly IE) will fallback to the hashtag approach if necessary.

Hope this helps!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top