【问题标题】:Backslash in URL path changing path to publicURL路径中的反斜杠将路径更改为公共
【发布时间】:2018-03-25 12:15:18
【问题描述】:

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

 <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"));

告诉浏览器去哪里搜索。

谢谢

【问题讨论】:

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


    【解决方案1】:

    如果你在测试后进入下一个级别(例如:mysite.com/test/example),你需要上一个级别,因为路径是相对的。

    试试:

    <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">
    

    现在,硬编码路径可能会在一段时间后变得烦人;您可能希望将这些路径作为本地人的一部分提供。

    【讨论】:

    • 是的,这很明显。我不知道为什么我没有建立这种联系。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    相关资源
    最近更新 更多