我的 index.js 路由文件有问题 - 我是否正确设置了我的视图?

Having some trouble with my index.js route file - have I set up my views correctly?

这是我的 routes/index.js:

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

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

module.exports = router;

这是我的 index.jade:

extends layout

block content

block top-menu

这是我的 layout.jade:

doctype html

html
  head
    title The Outpost
    meta(charset='utf-8')
    meta(name='viewport', content='width=device-width, initial-scale=1.0')
    link(href='stylesheets/style.css', rel='stylesheet')
    link(href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css", rel="stylesheet")
    link(href='https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', rel='stylesheet')
  body
    block content
    block top-menu

这是我的顶-menu.jade:

extends index

block top-menu
  <!-- menu -->

如何在使用 res.render('index'); 时显示我的菜单?还是我对翡翠传承的理解有误?

我使用这个网站来了解:http://www.learnjade.com/tour/template-inheritance/

您实际上必须使用 res.render('top-menu') 才能像您设置的那样工作。我建议使用 include 将顶级菜单带入您的布局。

doctype html

html
  head
    title The Outpost
    meta(charset='utf-8')
    meta(name='viewport', content='width=device-width, initial-scale=1.0')
    link(href='stylesheets/style.css', rel='stylesheet')
    link(href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css", rel="stylesheet")
    link(href='https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', rel='stylesheet')
  body
    block content
    include top-menu

注意:如果您希望顶部菜单实际显示在内容上方,则需要将顶部菜单移动到内容上方。

这样您就不必在顶级菜单中扩展任何内容,也不必声明要覆盖的块,因为它只会包含在布局中。

<!-- top-menu.jade -->
<ul>...</ul>