Express.js和jade/pug中的路由没有路由,并且总是崩溃



下面是我的联系人路由器:

var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.render('contact');
});
module.exports = router;

我的app.js和server.js如下:

// app.js
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const port = 5000;
//
// ----------------------------------------------------------------
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
// -------------------------------
var contactRouter = require('./routes/contact');
var mealRouter = require('./routes/meal');
var gadginRouter = require('./routes/gadgin');
var aboutRouter = require('./routes/about');
// ----------------------------------------------------------------
var app = express();
//app.listen(port, () => {
//console.log(`Server started at port ${port}`);
//});
// view engine setup
//app.set('views', path.join(__dirname, 'views'));
//app.set('view engine', 'jade');
// ----------------------------------------------------------------
app.set('views', './views');
app.set('view engine', 'jade');
app.get('/', (req, res, next) => {
res.render('index');
});
app.get('/member/:name/planet/:home', (req, res) => {
const memberDetails = {
member: req.params.name,
planet: req.params.home
}
res.render('guardian', memberDetails);
});
app.get('/contact', (req, res) => {
res.render('contact');
});
app.get('*', (req, res, next) => {
res.status(200).send('Sorry, page not found');
next();
});
app.listen(port, () => {
console.log(`Server started at port ${port}`);
});
// ----------------------------------------------------------------
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
//----------------------------------------------------------------
app.use('/about', aboutRouter);
app.use('/contact', contactRouter);
app.use('/gadgin', gadginRouter);
app.use('/meal', mealRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
// 
//app.get('/', (req, res, next) => {
//    res.render('index');
//});
//
module.exports = app;
// index.js
var express = require('express');
var router = express.Router();
var app = express();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index');
});
module.exports = router;

我希望能够路由到'/'到索引。玉石页和"/联系人"进入联系人。哈巴狗页面。由于某种原因,我一直收到与标题相关的错误。我是新手。我得到了一条工作的路线,它是守护路线。

doctype html
html
head
title Express.js + Pug Demo
body
h1 Welcome, Guardian!
div Member: #{member}
p Planet: #{planet}

我的指数。玉和联络。

extends layout
block content
h1= WELCOME!
p Welcome to X, we are trying to figure out the title. HAPPY ERRORS!
p Hello world!

li About Miss.Rican 
li Meal Plan Generator 
li The GadGin 
li Contact Information
li Gadfit Data Base 
li Contribute to the project
p Gadfit is the ultimate fitness engine and application. With tailored 
p algorithms, work out programs, custimization and meal plans you or your trainer can 
p create, modify and learn more about fitness in a way never before seen. 
p This is a companion fitness program and is meant to assist and direct clients. 
p Trainers can use Gadfit to explain their programs, make new fitness plans, custimize meals plans and set up meetings. 
//a(href=url) 

我一直被路由到我的error.js页面和IDK为什么当我删除jade文件和其他相应文件中的${title}标签时,它一直引用标题。我是路由的新手,我想掌握它,但我被卡住了。我承诺一旦我掌握了路由的艺术,就会为社区做出贡献。路由是必要的和性感的。

//error.jade
extends layout
block content
h1= message
h2= error.status
pre #{error.stack}
extends layout 
block content
h1= 'Contact Information'
li Name: Noah Cameron Q'yain 
li City: New York City 
li State: New York State 
li Country: New York State
li Phone Number: 862-226-6380
li Email: noah.qyain@gmail.com 
li Fax: noah.qyain@gmail.com
li Github: noah.qyain@gmail.com
我明白了!在/views/布局中。当有一个对标题的引用并且扩展到其他视图并导致错误时,我将其更改为等于hello world!
doctype html
html
head
title = 'hello world'
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content

https://www.youtube.com/watch?v=pCAzGDrtvUY

相关内容

  • 没有找到相关文章

最新更新