Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MEAN stack: angular routing vs express routing [closed]

Tags:

I've started using angular in my express generated projects and i'm loving it. Recently I implemented angular routing into one of my test projects and I'm wondering what the advantages and disadvantages are to using angular routing over pure express/node routing (e.g. are there technical issues with this way, or maybe SEO, or is it totally unnecessary).

FYI on my setup: I have express rendering the main index template as well as routing all request (a catch all) to the main index template and then I'm using angular to route to partial templates from within the main index template

like image 463
zero Avatar asked Feb 11 '15 16:02

zero


People also ask

What is Express used for in mean stack?

Basically, what Express does is that it enables you to easily create web applications by providing a slightly simpler interface for creating your request endpoints, handling cookies, etc.

What is Express routing?

Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, and so on). Each route can have one or more handler functions, which are executed when the route is matched.

What is the correct order of defining routing using Express methods are?

The order is first come first serve. In your case, if user hits /api, he will get response from api, but if you write /:name route before /api , /:name will serve for /api requests also.

What are the routes in angular?

The routes are the JavaScript objects where we define which URL part of our app should be presented. We create a constant, which is of type Routes, which we also need to import this from the '@angular/router'. This constant holds an array of JavaScript objects, and each object has a certain structure.

How do I get angular to load a profile route only?

Angular allows you to define a route guard, which can run a check at several points of the routing life cycle to determine if the route can be loaded. We’ll use the CanActivate hook to tell Angular to load the profile route only if the user is logged in. $ ng generate guard auth ? Which interfaces would you like to implement?

How to access employee data through RESTful APIs in angular?

My data types are name, email, designation and phoneNumber. Add the given below code in backend > models > Employee.js file. Let us create the routes in Angular app to access the Employee data through RESTful APIs.

Is the MEAN stack the right choice for your application?

While the MEAN stack isn’t perfect for every application, there are many uses where it excels. It’s a strong choice for developing cloud native applications because of its scalability and its ability to manage concurrent users.


2 Answers

With the mean stack (mongo, express, angular) you will have routing at both ends.

Express will serve your static index.html and css/js/images and your api, and angular will interact with the api to get data from mongo.

Routing with express will primarily be done for the API, and routing in angular will be done to handle the front-end of your application. Express will not return any html other than the index.html and any template partials that you have written for angular, however even that can be eliminated by compiling all of the templates directly into your js files using a build-tool such as gulp/grunt.


It certainly is possible to go 100% to one side or the other, however, it's impractical because you'll end up inefficiently using one side or the other. For example, if you did all of your routing with express and used angular on each individual page, you would be ignoring all of the single page app functionality and routing of angularjs, leaving it's only purpose being building the page which could probably be done more effectively with express and jade (or any other templating engine.) It isn't really possible to go in the other direction and do all of your routing with angular because angular requires an api to get data from, unless you include all of the data up front inline in the html, which i'm sure you'll agree is a bad idea. (it also eliminates mongo at that point..)

like image 102
Kevin B Avatar answered Oct 11 '22 11:10

Kevin B


They are solving two different problems. Angular routing (ui-router) is client-side - loading the correct ui-views. Express routing is server-side - the REST APIs you are exposing.

like image 26
Brad Barber Avatar answered Oct 11 '22 10:10

Brad Barber