快递 + Jade:通过控制器、孤立链接确保 url 路径正确?
我来自使用 Play!框架,将链接放入涉及使用控制器对象然后选择方法的模板中。例如 @{Controller.method(passedValue)} 这真的很棒。
在我的第一个express/node项目中,我担心有孤立的链接,例如/user/new变成/register。我如何避免这个问题?
I have come from using the Play! Framework where putting links in a template involved using the controller object then selecting a method. E.g. @{Controller.method(passedValue)} which was really wonderful.
With my first express/node project I am worried about having orphaned links e.g. /user/new becomes /register. How do I avoid this being a problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,javascript 是一种动态解释语言。您永远不会有任何编译器会通知您损坏的链接。即使您从在模板中使用 URL 路径切换为从控制器对象获取属性(这很好),您也必须担心这两种情况下的孤立链接。编写测试以确保这些东西不会损坏。
仅供参考,欢迎您对玉石/快递做同样的事情。当您调用jade.render时,将控制器对象放入“locals”变量中,然后在您的模板中,
如果您觉得这样更干净,您可以执行以下操作或类似的操作。但是,如果您将 registerURI 方法重命名为 loginURI,您就必须担心如何更新该代码以匹配。这就是解释性语言的本质。
Well, javascript is a dynamic interpreted language. You'll never have any compiler that will notify you of broken links. Even if you switch from using URL paths in your templates to getting attributes from a controller object (which would be fine), you have to worry about orphaned links in both cases. Write tests that make sure this stuff doesn't break.
FYI you are welcome to do the same thing with jade/express. Put the controller object into the "locals" variable when you call jade.render, and then in your template you can do
or something along those lines if you feel that's cleaner. But still, if you rename the registerURI method to loginURI, you have to worry about going and updating that code to match. That's the nature of an interpreted language.