简体   繁体   English

从localhost:3000 / admin到localhost:3000

[英]From localhost:3000/admin to localhost:3000

I am building a node.js app. 我正在构建一个node.js应用程序。 I would like that after the admin has successfully uploaded data the homepage is rendered, that is, from localhost:3000/admin to localhost:3000 . 我想要在管理员成功上传数据后呈现主页,即从localhost:3000/adminlocalhost:3000 I've tried with the code below: 我试过下面的代码:

router.post('/', (req, res)=>{upload(req, res, function(err) {
  if (err) {
    console.log(err);
    res.render('admin', {msg: err});
  }else{
    return res.redirect('index');
  }
}

and this is the index.js code: 这是index.js代码:

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

module.exports = router;

but despite the title being defined index.js and express routing being fine am getting the error: 但是尽管标题已定义为index.js且表达路由很好,但仍收到错误:

ReferenceError: E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\views\index.ejs:4
    2| <html>
    3|   <head>
 >> 4|     <title><%= title %></title>
    5|     <link rel='stylesheet' href='/stylesheets/style.css' />
    6|   </head>
    7|   <body>

title is not defined

If you want send variable title from your server, change this line: 如果要从服务器发送变量title ,请更改以下行:

res.render('admin', {msg: err});

to: 至:

res.render('admin', {msg: err, title: <your title here>});

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

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