MEAN堆栈:角度路由与快速路由 [英] MEAN stack: angular routing vs express routing

查看:72
本文介绍了MEAN堆栈:角度路由与快速路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始在我的快递生成的项目中使用angular,并且我喜欢它.最近,我在我的一个测试项目中实施了角路由,我想知道在纯快速/节点路由上使用角路由有什么优点和缺点(例如,这种方法是否存在技术问题,或者可能是SEO,还是全部不必要).

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

在我的设置中仅供参考:我已经表达了渲染主索引模板以及将所有请求(全部捕获)路由到主索引模板的过程,然后我使用angular从主索引模板内部路由到部分模板

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

推荐答案

使用平均堆栈(mongo,express,angular),您将在两端都进行路由.

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

Express会为您的静态index.html和css/js/images以及您的api提供服务,而angular将与api进行交互以从mongo获取数据.

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.

使用express进行路由主要是针对API,并且将进行角路由以处理应用程序的前端. Express不会返回除index.html之外的任何html以及您为angular编写的任何模板部分,但是即使这样,也可以通过使用诸如gulp/grunt之类的构建工具将所有模板直接编译到js文件中来消除

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.

当然有可能100%移到一侧或另一侧,但这是不切实际的,因为您最终将无法有效地使用一侧或另一侧.例如,如果您在每个页面上都使用express和used angular进行了所有路由,则您将忽略所有单页面应用程序功能和angularjs的路由,剩下的唯一目的是构建可以做得更多的页面使用express和jade(或任何其他模板引擎)有效地实现.实际上不可能朝另一个方向进行角度的所有路由,因为除非您包括所有数据,否则角度需要从中获取数据的api.在html中进行内联,我相信您会同意这是一个坏主意. (这时也消除了mongo.)

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

这篇关于MEAN堆栈:角度路由与快速路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆