快递路由的URL生成 [英] URL Generation for Routes in Express

查看:217
本文介绍了快递路由的URL生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑在我下一个node.js项目中使用Express框架。然而,对于我来说,一个绊脚石是不存在URL生成的路线,像大多数其他非Sinatra的框架,例子 - Django,Flask,Rails等。



我尝试寻找一些Connect中间件来为我的任务服务,我找到了Barista,Escort,Sherpa等,但是看着他们的GitHub页面,似乎都是死的和活跃的。所以,我不想因为明显的原因去寻找不再被维护的东西。



我的主要关注是项目可能会变得很大,每当商业和/或美学需求改变时,每个页面更新URL的痛苦。



有没有在docs / tests中看不到的东西?如果没有,那么如何在Express中扩展路由框架来生成URL,并在我的视图和控制器函数中使这个包装器可用?



更新:(22/3/2012)我发现这个页面: https://github.com/clyfe/tweet_express / wiki / TODO ,它指定了一些执行URL生成的路由器,并且绊倒了可以与express相关联的护送路由器。

解决方案

您可以尝试机车,其基于Express。



它比路由生成更多。从文档:机车带来额外的基于MVC的结构,用于构建更大的应用程序,同时利用Express和Connect中间件的力量。



机车的路由器生成助手,这些帮助器可以自动提供给控制器和视图。


I'm considering using Express framework in my next node.js project. However, a stumbling block for me is non-existence of URL generation for routes like in most other non-Sinatra based frameworks, examples- Django, Flask, Rails etc.

I tried looking for some Connect middleware to serve my task and I did find Barista, Escort, Sherpa and the likes but looking at their GitHub pages, all seem dead and in-active. So, I don't want to go for something that's not maintained anymore for obvious reasons.

My main concern here is that the project may get really large and it WILL be a pain to update URLs in every page whenever business and/or aesthetic requirements change.

Is there something that I failed to see in the docs/tests? If not, then how do I extend the routing framework in Express to do URL generation and make this wrapper available in my views as well as controller functions?

UPDATE: (22/3/2012) I found this page: https://github.com/clyfe/tweet_express/wiki/TODO which specified some routers that do URL generation and stumbled upon the escort router which can also interface with express.

解决方案

You might try Locomotive, which is built on Express.

It does much more than route generation. From the docs: "Locomotive brings additional MVC-based structure, for architecting larger applications, while leveraging the power of Express and Connect middleware."

Locomotive's router generates helpers that are automatically available to controllers and views.

这篇关于快递路由的URL生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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