NodeJS + Express:为不同的URL提供静态文件 [英] NodeJS+Express: serving static files for diffrerent URLs

查看:49
本文介绍了NodeJS + Express:为不同的URL提供静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用node.js + express来提供静态文件(CSS + JS).此时,静态目录配置为

I'm using node.js+express for serving static files (CSS+JS). At this time static dir is configured as

app.use(express.static(__dirname + '/static'));

在主模板布局中,我将静态文件加载为

In main templeate layout.jade I load static files as

link(href='css/bootstrap.css', rel='stylesheet')

一切都适用于/hello,/write,/:user等页面.但是,当我获得/bob/505b6833d3835d3705000001/edit之类的页面时,找不到静态文件.Firebug显示Node会为静态生成相同的路径,但是样式不适用于该页面.为什么?预先感谢!

Everything works fine with pages like /hello, /write, /:user. But when I get pages like /bob/505b6833d3835d3705000001/edit, static files cannot be found. Firebug shows Node generates the same path for static, but styles are not applied for the page. Why? Thanks in advance!

推荐答案

您应该使用带有斜杠的链接.

You should be using link with pre-slash.

link(href='/css/bootstrap.css', rel='stylesheet')

这应该照顾它.

这篇关于NodeJS + Express:为不同的URL提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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