Express.js or angular for handling routes in a MEAN application?

前端 未结 1 1115
悲哀的现实
悲哀的现实 2021-01-30 13:58

I am totally new to everything Nodejs/express/angular, and I just ran into a question that bothers me.

When you have a MEAN stack, it seems that routes can be handled by

1条回答
  •  失恋的感觉
    2021-01-30 14:26

    Those two serve different purposes on a single page app.

    The app would do all the CRUD (endpoints where you create/read/update/delete your stuff, for example: projects, users, bills, etc). Also it would do all the authentication stuff (like /login and /register).

    All of that needs routes, because you would want something like /api/users to grab all your users. All those routes, AKA CRUD routes and authentication routes goes into express.js router. Why there? Because those are routes of the backend.

    On the other hand, you have your angular application, which contains the visual part of your application and there you want some routes. You want / to point to your home, you would want /users to have a page where you list your users or even /users/add to have a page with a form to add new users.

    You could see it this way:

    Backend routes (express ones): Those are the routes that an end user won't have to know about or even use them (your angular app will use them to communicate with the backend to work with its data but an end user wouldn't put them directly on the browser)).

    Frontend routes (angular ones): Are the routes that maps to different pages of your application and because of that, end users can use them to access some parts of your application directly.

    0 讨论(0)
提交回复
热议问题