本文介绍了防爆press.js或角在平均处理应用程序的路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是全新的一切的NodeJS / EX preSS /角度,我只是碰到了困扰我的一个问题。

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

当你有一个堆栈MEAN,似乎可以航线由双方办理防爆press.js

When you have a MEAN stack, it seems that routes can be handled by both Express.js and Angular.

举例来说,如果我定义角路线,我能做到这一点是这样的:

For instance, if I define a route in Angular, I can do it like this:

var app = angular.module("app", []).config(function($routeProvider) {
    $routeProvider.when('/login', {
        templateUrl: '/templates/login.html',
        controller: 'LoginController'
    });

    $routeProvider.when('/front', {
        templateUrl: '/templates/front.html',
        controller: 'FrontController'
    });


    $routeProvider.otherwise({redirectTo: '/front'})
});

但是,与前press.js我

app.get('/',function(req,res){
    res.sendfile('templates/angular.html');
});

所以我的问题是

当你用角路由,当你使用前preSS路由?

When do you use angular routing, and when do you use express routing?

(我可能会错过一些很明显的在这里,但我希望你能指出来)

(I might miss something very obvious here, but I hope you can point it out)

推荐答案

这两个在一个页面的应用程序服务于不同的目的。

Those two serve different purposes on a single page app.

该应用程序会做所有的CRUD(你创建/端点读取/更新/删除你的东西,例如:项目,用户,票据等)。此外,它会做所有的东西的认证(如 /登录 /寄存器)。

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).

所有需要的路线,因为你想要的东西,像 / API /用户来获取所有用户。所有这些路线,AKA CRUD路线和认证途径进入前press.js 路由器。为什么呢?因为这些都是后端的路线。

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:

后端线路(例如preSS的):这些都是最终用户不必了解甚至使用它们(您的角度应用程序将使用它们与后端进行通信,其数据的工作路线但最终用户不会把他们直接在浏览器上))。

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.

这篇关于防爆press.js或角在平均处理应用程序的路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 17:48