Express(路由中断)

模板引擎

常见模板引擎有pug,handlebars,ejs等

由占位符所组成的部分会被后端用相应数据进行填充

  • index.js
<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
    <h1><%= title %></h1>
    <p>Welcome to <%= title %></p>
  </body>
</html>
  • error.js
<h1><%= message %></h1>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>

路由中断

  • express规定,如果router.use()中next()内容为'router',则当前路由终止。
var express = require('express');
var router = express.Router();

router.use('/', function(req, res, next) {
 console.log('mv1')
 next('router')
});
router.use('/', function(req, res, next) {
    console.log('mv2')
    next()
   });
   
module.exports = router;
mv2不显示
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容