search

Home  >  Q&A  >  body text

node.js - node的express怎么设置初始页面

就是怎么配置可以只输入域名后面不带参数,访问默认的页面。类似于asp.net的起始页。

ringa_leeringa_lee2778 days ago1074

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 11:43:33

    Can’t this project automatically generated by express be able to achieve such a function? !

    There are a few sentences in the automatically generated project app.js

    var routes = require('./routes/index');
     ..........
    app.use('/', routes);
    

    The content of ./routes/index.js is similar to

    var express = require('express');
    var router = express.Router();
    
    router.get('/', function(req, res, next) {
      //这里就是生成你默认页面的代码
      //下面这句的意思是用一个叫做index的模板生成页面
      res.render('index', { title: 'Chat' });
    });
    
    module.exports = router;
    

    reply
    0
  • Cancelreply