我正在使用node创建一个页面,其中安装了express和express-handlebar包。我正在尝试创建一个跨所有页面的菜单,通过该菜单,我可以通过单击按钮跳转到页面。我的前两个超链接运行良好,然后当我决定添加一个aboutMe页面和一个测试页面时,它们都重定向到404。文件结构
static.js
|
Views
---home.handlebars
---404.handlebars
---other-page.handlebars
---aboutMe.handlebars
---testing.handelbars
Layouts
|
main.handlebars我的static.js上的代码:
var express = require('express');
var app = express();
var handlebars =require('express- handlebars').create({defaultLayout:'main'});
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.set('port', 3000);
app.get('/', function(req,res){
res.render('home');
}
app.get('/other-page', function(req,res){
res.render('other-page');
});
app.get('/aboutMe', function(req,res){
res.render('aboutMe');
});
app.get('/testing', function(req,res){
res.render('testing');
});
app.use(function(req,res){
res.status(404);
res.render('404');
});
app.use(function(err,req,res,next){
console.error(err.stack);
res.type('plain/text');
res.status(500);
res.render('500');
});
app.listen(app.get('port'), function(){
console.log('Express started on http://localhost:' + app.get('port') +'; press Ctrl-C to terminate.');
});来自我的main.handlebars的一个片段,其中我链接:主页其他-关于测试的页面
发布于 2016-05-21 08:52:51
我们会,经过几个小时的拼命我已经解决了我的问题。我意识到我让node永远在static.js上运行,我对文件进行了更改,直到我停止并重新启动了static.js上的node,这些更改才会发生。:)
https://stackoverflow.com/questions/37357687
复制相似问题