简体   繁体   English

Express Handlebars-Page正在路由到404

[英]Express Handlebars-Page is routing to 404

I'm creating a page using node which has the express and express-handlebars packages installed. 我正在使用安装了express和express-handlebars包的节点创建页面。 I'm trying to create a menu across all of my pages through which I can jump to pages by clicking a button. 我正在尝试在我所有页面上创建一个菜单,通过单击一个按钮可以跳到这些菜单。 My first 2 hyperlinks worked fine, then when I decided to add an aboutMe page and a testing page, they both redirect to 404. File Structure 我的前2个超链接工作正常,然后当我决定添加aboutMe页面和测试页面时,它们都重定向到404。文件结构

static.js static.js

 |
Views

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

Code on my static.js: 我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.');
});

A snippet from my main.handlebars where im linking: Home Other-Page About Testing 我的main.handlebars中的一个片段,它们之间是im链接:主页其他-关于测试的页面

We'll,after hours of headbanging i've solved my problem. 经过数小时的紧张交往,我们会解决我的问题的。 I realize that I had node forever running on static.js, i made changes to the file, and those didn't take place until i stopped and restarted node on static.js. 我意识到我的节点永远在static.js上运行,我对文件进行了更改,直到我停止并重新启动static.js上的节点之后,这些更改才发生。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM