Express / node新手,只是构建了一个简单的代码。
我测试了网址" localhost:3000 / detail",它运行正常。但是,我测试了网址" localhost:3000 / detail / test1",页面显示不正确。
第二个功能" /" " / test1"正确渲染页面没有,我已经检查了css的目录;无法理解。
detail.controller.js
//page are not correct
router.get('/test1', function (req, res) {
res.render('detail');
});
//page correctly shown with css style
router.get('/', function (req, res) {
res.render('detail');
});
server.js
app.use('/detail', require('./controller/detail.controller'));
app.use("/css-detail", express.static(__dirname + '/app/detail/css'));
app.use("/js-detail", express.static(__dirname + '/app/detail/js'));
app.use("/img-detail", express.static(__dirname + '/app/detail/img'));
app.use("/fonts", express.static(__dirname + '/app/detail/fonts'));
detail.ejs(partial)
<head>
...
<!-- Bootstrap -->
<link rel="stylesheet" href="css-detail/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="css-detail/font-awesome.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="css-detail/owl.carousel.css">
<link rel="stylesheet" href="css-detail/style.css">
<link rel="stylesheet" href="css-detail/responsive.css">
</head>
答案 0 :(得分:0)
稍微更改了代码,并在'css-detail之前添加'*',现在它可以正常工作。 ..
app.use("/*css-detail", express.static(__dirname + '/app/detail/css'));