admin管理员组文章数量:1406951
I have built several Backbone apps and appreciate the client-side code structure and organization. I'm moving into Node development, using Express, and I'm uncertain as to how Express and Backbone can work together in the handling of routes.
I have built several Backbone apps and appreciate the client-side code structure and organization. I'm moving into Node development, using Express, and I'm uncertain as to how Express and Backbone can work together in the handling of routes.
Share edited Dec 17, 2012 at 18:36 AndrewHenderson asked Dec 17, 2012 at 9:17 AndrewHendersonAndrewHenderson 4,9923 gold badges29 silver badges34 bronze badges 1- Backbone.Router is for client-side routing, ie: using the html5 history API to change the URL when you update the page via ajax. What are you trying to do? – jordanj77 Commented Dec 17, 2012 at 11:10
3 Answers
Reset to default 3You need to understand that Node and Backbone are independent from each other.
- Node is for server-side (e.g working with a database, api serving etc. ) .
- Backbone is a client-side Javascript MVC framework which gives you a structure for organizing your client-side Javascript application. (the application in the browser)
You can have a Backbone application in your client-side and it can hook up to any back-end either Node, Rails, PHP etc...
For more info check MVVM pattern and Javascript frameworks on the client-side.
http://backbonetutorials./why-would-you-use-backbone/
http://addyosmani./blog/understanding-mvvm-a-guide-for-javascript-developers/
A friend gave me the answer:
Backbone uses hash routes. For instance http://yoursite./#foo
Express will use the traditional http://yoursite./foo
You can use the routers independent of one another based one which address you path to - a hash route for client-side functions and the traditional route for server side functionality.
Both routers can coexist.
Your question on how Backbone and Express can work together cannot really be answered precisely, because there are really countless ways on which they can work together. Hopefully some of the info below can help you do what you want to do.
First of all, you can use www.example./foo (no #) routes on the client side (Backbone) - see the pushState
option in Backbone.history.start() documentation. It is possible to integrate the routes on the client side and on the server side. It is not easy to find exactly how to do, though.
Some of the info under those links may help you:
- https://github./developmentseed/bones
- https://github./SC5/backbone-serverside
- https://github./tysoncadenhead/backbone-on-express
- http://nerds.airbnb./weve-launched-our-first-nodejs-app-to-product
- http://blog.andyet./2011/feb/15/re-using-backbonejs-models-on-the-server-with-node/
You wrote that you have experience with Backbone but you're moving to Node recently so I assume that you are open to other frameworks than only Express. You may consider using eg. restify (in addition to Express) to make a RESTful service which you can integrate with Backbone.
There are also entire frameworks like Derby or Meteor that cover both client side and server side using one code base and you can share much more than just the routers.
(Also, I've just found this year's (2013) HTML5DevConf talk: Surviving Robots and Old Browsers by Server-side Backbone. I haven't watched it yet but it seems very relevant to your problem.)
本文标签: javascriptCan Backbone and Express routers work together in an Express applicationStack Overflow
版权声明:本文标题:javascript - Can Backbone and Express routers work together in an Express application? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744948105a2633909.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论