[英]node.js express.js routes slash css
when i write localhost/profil the css works. 当我写本地主机/配置文件的CSS工作。 But when i write localhost/profil/ the css doesn't work. 但是,当我写localhost / profil /时,css不起作用。
app.use(express.static(__dirname+'/public'));
app.get('/profil',[checkCo],require('./routes/profil.js'));
Why? 为什么?
thanks! 谢谢!
edit: 编辑:
it's because it thinks that profil/ is a folder, so how can i get around this? 这是因为它认为profil /是一个文件夹,所以我该如何解决?
You likely need to use absolute paths within your HTML. 您可能需要在HTML中使用绝对路径。
For example, instead of 例如,代替
<link rel="stylesheet" href="style.css">
you need to do 你需要做
<link rel="stylesheet" href="/style.css">
In the first example, the browser tries to access style.css
in the current directory the user is navigated to. 在第一个示例中,浏览器尝试访问用户导航到的当前目录中的style.css
。 So if the user is navigated to /profil/
, it tries to load the css from /profil/style.css
. 因此,如果用户导航到/profil/
,它将尝试从/profil/style.css
加载css。 In the second example, the browser is told to load the css from /style.css
no matter what. 在第二个示例中,告诉浏览器/style.css
从/style.css
加载CSS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.