Yuity

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1. 假定,当所有的路径都没有匹配的时候,我们就给它返回一个404页面。

  首先,打开index.js,在function checkLogin(req, res, next){} 的前面添加如下所示代码:

router.use(function(req, res) {
        res.render('404');
    })

  然后,我们在views文件下创建一个404.ejs的文件,用来保存404页面,在其中添加如下代码:

<!DOCTYPE html>
<html>
<head>
      <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>MicroBlog</title>
</head>
<body>
    <div>
        <a href="http://imooc.com/">
            <img id="error404-image" alt="404 page not found" src="http://huwshimi.com/wp-content/themes/huwshimi/images/404.png" style="width:100% height:100%">
        </a>
    </div>
</body>
</html>

  至此,我们就给页面添加了一个美丽的404页面。

 

posted on 2016-03-22 10:39  Yuity  阅读(179)  评论(0编辑  收藏  举报