Javascript 更改路由器时无法正确呈现页面
新到Express/node,并且只构建了一个简单的代码 我测试了url“localhost:3000/detail”,它运行良好。但是,我测试了url“localhost:3000/detail/test1”,页面没有正确显示 第二个函数“/”正确呈现页面,而“/test1”没有,我已经检查了css目录;我想不出来 detail.controller.jsJavascript 更改路由器时无法正确呈现页面,javascript,html,css,node.js,express,Javascript,Html,Css,Node.js,Express,新到Express/node,并且只构建了一个简单的代码 我测试了url“localhost:3000/detail”,它运行良好。但是,我测试了url“localhost:3000/detail/test1”,页面没有正确显示 第二个函数“/”正确呈现页面,而“/test1”没有,我已经检查了css目录;我想不出来 detail.controller.js //page are not correct router.get('/test1', function (req, res) {
//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(部分)
...
稍微更改了代码,在css细节之前添加了“*”,现在它可以工作了
app.use("/*css-detail", express.static(__dirname + '/app/detail/css'));
请详细说明“页面未显示更正”不正确意味着没有为ejs加载css文件,并且ejs没有样式。
app.use("/*css-detail", express.static(__dirname + '/app/detail/css'));