【问题标题】:Error to get css in express在 express 中获取 css 时出错
【发布时间】:2017-05-29 22:40:15
【问题描述】:

当我尝试联系 http://localhost:3000/contato/1 时,我收到了下面的错误

GET http://localhost:3000/contato/static/bootstrap/dist/css/bootstrap.min.css 404 (Not Found)

这是由这条路线定义的:

app.route('/contato/:id')
    .get(autenticar, contatos.show);

在其他没有 :id 参数的路由中,css 渲染得很好。

我正在使用 Pug 开发页面,并通过公共文件夹提供静态文件,使用:

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

我的 header.pug,我在每一页中扩展。

doctype html
html
head
    link(href='static/bootstrap/dist/css/bootstrap.min.css' rel='stylesheet')
    meta(charset='utf-8')
    meta(name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no")
    title Ntalk - Agenda de Contatos
body
    div(class='container')
        block content

出现错误的路线:

show.pug

include ../header
  block content
    div(class='row')
      div(class='col-md-6 offset-md-3')
        section(class='container')
          header
            h2 Ntalk - Dados do contato

【问题讨论】:

    标签: css express pug


    【解决方案1】:

    您应该在 header.pug

    中更改指向 css 的链接(通过在开头添加 /
    link(href='/static/bootstrap/dist/css/bootstrap.min.css' rel='stylesheet')
    

    否则与当前页面相关

    【讨论】:

      猜你喜欢
      • 2017-04-22
      • 2016-11-21
      • 2019-02-24
      • 1970-01-01
      • 2018-02-10
      • 2014-09-27
      • 1970-01-01
      • 2020-07-21
      • 1970-01-01
      相关资源
      最近更新 更多