Link to static files from Jade template rendered from a sub route
Node.js / Express / Jade有一个非常基本的问题,很难描述。在我的node.js应用程序中,我使用Express框架路由HTTP请求。我还使用Jade模板作为视图,它们本身链接到通过
当我将请求路由到
所以我的假设是,由资源级别代表的虚拟目录在jade认为它必须寻找相对路径的地方搞砸了(在这种情况下,是在哪里找到包含静态文件的
我不能只在玉模板中添加路径前缀,因为我必须对不同的资源类型使用相同的模板,因此我需要一种适用于任意资源级别的解决方案。
有这样的解决方案吗?
我猜您的Jade模板具有如下外观:
1 2 3 4 | doctype html head link(rel="stylesheet", type="text/css", href="css/style.css") ... |
样式表的
-
http://example.com/about →http://example.com/css/style.css -
http://example.com/about/company →http://example.com/about/css/style.css
您可以将
1 | link(rel="stylesheet", type="text/css", href="/css/style.css") |
此处的关键更改是