呈现页面时不添加样式

问题描述 投票:0回答:1

呈现页面时,我的样式有问题。在任何其他页面上连接样式都没有问题这是哈巴狗与product.pug:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="styles/main.css">
    <title>#{product.product_name}</title>
</head>
<body>
    <header>
        include layout/menu.pug
        include layout/myProfile.pug
    </header>
    <main>
        | there will be data about the product
    </main>
    include layout/footer.pug
</body>
</html>

这是app.js的代码:

app.get('/product/:productId', (req, res) => {
    if (req.params["productId"] !== undefined &&
        req.params["productId"] > 0) {
        conn.query(`SELECT * 
                    FROM product
                    WHERE product_id = ${req.params["productId"]}`, (err, product) => {
            if(err) {throw err;}
            if(product.length > 0) {
                res.render('product', {
                    userName: req.session.userName,
                    successAuthentication: req.session.successAuthentication,
                    isWorker: req.session.isWorker,
                    product
                })
            } else {
                res.sendStatus(404);
            }
        });
    } else {
        res.sendStatus(404);
    }
});

样式存储在公用文件夹中,而app用于使用styles.use(express.static(path.join(__ dirname,'public')));;其他任何页面都没有渲染样式问题。我无法解决此问题,因此我将不胜感激

node.js express pug
1个回答
0
投票

您可以像下面的代码一样设置快速静态文件夹:

app.use(expresss.static('public'));

现在,您可以尝试在应用程序根目录中创建public文件夹,并将styles文件夹移到public文件夹中,并且其工作正常。

我希望它能为您提供帮助。

© www.soinside.com 2019 - 2024. All rights reserved.