【发布时间】:2019-07-02 14:24:19
【问题描述】:
我的快递应用有问题。有一些 ejs 模板,其中正确应用了 css 样式文件。例如“localhost***/page”,但是当我转到“localhost***/page/secondpage”时,即使我应用它,我的 ejs 也看不到样式。
一点代码 app.js
app.use(express.static(path.join(__dirname, 'public')));
//some code
app.use('/', require('./routes/index'));
app.use('/events', require('./routes/events'));
一些路线
const express = require('express');
const router = express.Router();
router.get('/', function (req, res, next) {
let query = *db query*;
res.locals.connection.query(query, function (error, results, fields) {
if (error) throw error;
res.render('index', { title: 'Events', data: results });
});
});
router.get('/:id', function (req, res) {
let query = *db query*;
res.locals.connection.query(query, function (error, results, fields) {
if (error) throw error;
res.render('singleevent', { title: 'Event', data: results });
});
});
localhost***/events 页面和下一页 localhost***/events/singleevent 的头
<head>
<meta charset="UTF-8">
<title>
<%= title %>|Minsk Events</title>
<link rel="stylesheet" href="css/style.css">
</head>
【问题讨论】: