URL路径中的反斜杠将路径更改为public

时间:2018-03-25 12:15:19

标签: amazon-web-services express path directory mean-stack

我的样式表在我的标题中链接为

 <link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/animate.css">
<link rel="stylesheet" href="css/meanmenu.min.css">

我在AWS Cloud9开发环境中使用MEAN堆栈,当我预览我的应用程序时,所有内容都完全符合我计划如何使用这些样式表,因为它们在我的公共目录中,但是当我添加时在预览中,样式表未链接到URL路径末尾的任何反斜杠。例如,样式表明显链接在mysite.com/test上,但mysite.com/test/或mysite.com/test/example似乎取消链接,所有内容都采用标准的原始HTML格式。如果我链接他们工作的CDN,但我也需要链接自定义样式表。

我有

app.use(express.static(__dirname + "/public"));

告诉浏览器搜索的位置。

由于

1 个答案:

答案 0 :(得分:0)

If you go to the next level after test (eg: mysite.com/test/example), you need to go up a level, since paths are relative.

Try:

<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" href="../css/font-awesome.min.css">
<link rel="stylesheet" href="../css/owl.carousel.min.css">
<link rel="stylesheet" href="../css/animate.css">
<link rel="stylesheet" href="../css/meanmenu.min.css">

Now, hardcoding your paths might get annoying after a while; you might want to provide these paths as part of your locals.

相关问题