0
명시 적 앱에 문제가 있습니다. CSS 스타일 파일이 올바르게 적용된 ejs 템플릿이 있습니다. 예를 들어, "localhost ***/page",하지만 "localhost ***/page/secondpage"로 이동하면 내 ejs는 스타일을 적용해도 그것을 보지 못합니다.Ejs 파일에 CSS 스타일이 표시되지 않습니다
코드 의 조금
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 });
});
});
로컬 호스트의 헤드 ***/이벤트 페이지와 다음 페이지의 로컬 호스트 ***/이벤트/singleevent의를 app.js
<head>
<meta charset="UTF-8">
<title>
<%= title %>|Minsk Events</title>
<link rel="stylesheet" href="css/style.css">
</head>
내가있다 : public/css/style.css 및 views/events.ejs 및 views/singleevent.ejs –