简体   繁体   中英

backbone,js and node.js render and routing

Hey guys well im new to backbone and to node and im trying to make my own web app, im using express on node. so iv done the express "myappname" command in the cmd and i got a beutiful structure of my app. add backbone jQuery and so on, now for as far as i understood i can route using express just like:

app.get("location" , require('./routes').index);

then on my routes/index

i got this middleware:

exports.index = function(req, res){
  res.render('index',
      { name: you });
};

im using handlebars too and my file index.html looks like this :

<div>
{{name}}
<div>

untill here everything is clear for me - when client requset "/" page he gets index.html page that is rendered using handlebars and passes an object to index.html which ouputs

<div>you</div>

my problem is when backbone comes in! backbone as routes too and render also..

so where should i render and route my app?

using node on the server? or using backbone on the client?

if i dont render my app on backbone can i still intercat with it using backbone for updating my model?

how do i render with backbone when using node? im so confuse! i know node it in the server side and spouse to take care for routes GET/POST/UPDATE etc requsets also conectting to DB and such, and that backbone is only taking care of the client side and sending a data back and forth.

i have read "Developing Backbone Apps" by Addy Osmani and he is showing one a RESTful web app using backbone and node but is not getting deep enough,he is not rendering on the server, and he does not routes multiple pages, he is just showing a simple get/post/update/delete requsets.

Dealer's choice. These frameworks have some overlap. You can render server side (express) or client side (backbone). I would recommend not doing both as it gets confusing pretty fast.

Most people using backbone do all the rendering on the client so all you really need on the backend is to serve up a static skeleton html page, and to create some api endpoints for backbone to hook into.

The way you are using express right now is more akin to a rails or php app. If you are building a backbone application you can skip the server side rendering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM