首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Express Handlebars寻呼路由至404

问Express Handlebars寻呼路由至404
EN

Stack Overflow用户
提问于 2016-05-21 08:30:17
回答 1查看 1.1K关注 0票数 0

我正在使用node创建一个页面,其中安装了express和express-handlebar包。我正在尝试创建一个跨所有页面的菜单,通过该菜单,我可以通过单击按钮跳转到页面。我的前两个超链接运行良好,然后当我决定添加一个aboutMe页面和一个测试页面时,它们都重定向到404。文件结构

static.js

代码语言:javascript
复制
 |
Views

  ---home.handlebars
  ---404.handlebars
  ---other-page.handlebars
  ---aboutMe.handlebars
  ---testing.handelbars
     Layouts
     |
      main.handlebars

我的static.js上的代码:

代码语言:javascript
复制
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的一个片段,其中我链接:主页其他-关于测试的页面

EN

回答 1

Stack Overflow用户

发布于 2016-05-21 08:52:51

我们会,经过几个小时的拼命我已经解决了我的问题。我意识到我让node永远在static.js上运行,我对文件进行了更改,直到我停止并重新启动了static.js上的node,这些更改才会发生。:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37357687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档