ui.router or express to configure the routes of each view

1

I am trying to develop an application in full-stack JavaScript. I knew the routing system that offers based on states with ui.router , but I've seen that has another system to return views with depending on the browser path.

Are they different, and totally compatible? And if it is the same, which of the two is more recommendable or more efficient?

    
asked by aSardon 26.01.2017 в 20:07
source

3 answers

0
  

Are they different, and totally compatible? And if it is the same, which of the two is more recommendable or more efficient?

They are different things. ui-router offers a mechanism to route which is the view (and controller) active at a given moment for a SPA (Single Page Application) and runs completely on the client .

Node.js runs on the server side and has no native way of doing server side routing, let alone client side. You must use some framework for the server side as express.js (or similar) or even create your own.

Not only compatible are complementary , a very common use case is to make an application in node.js (with express for example) that has a single endpoint (or server side path) to obtain all the resources of the SPA (the html, your javascript, your css, libraries, client side etc) and many other endpoints (other server side routes) forming a REST API service that the SPA consumes via AJAX to access the data of the application, usually communicating via json.

    
answered by 26.01.2017 / 20:50
source
0

The response of Emanuel Ve, is fundamental, hence depends on how you structure this application, if with only 1 application or sub application SPA, or several SPA applications that have different urls, there would be to define them in NodeJs, and having loaded the sub application SPA, you can manage at the angular level with routes url on the client side, and from that last NodeJs would not be aware

Generally speaking, the SPA application is 1 only, it starts with 1 url, it will handle Node, then it has in its SPA behavior, some client-side routes (defined in angularJS, that is, on the client side), and maybe some interaction with other URLs, server side, if for example you have to go to authenticate where third parties

Therefore you have to completely master both possibilities, and reaffirm the idea expressed by Emanuel, could not add more without redundar

    
answered by 26.01.2017 в 21:05
0

And if you are going to use the fundamental angle html5 mode in the server you always set the index to refresh, since the angular paths (either uirouter or ngrouter) are going to break because they are abstract.

app.all("/*", function(req,res) {
  res.sendFile(__dirname + "index.html"); // ruta al index
});
    
answered by 26.01.2017 в 22:52