简体   繁体   English

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

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

This is my routes/index.js: 这是我的路线/ 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;

This is my index.jade: 这是我的index.jade:

extends layout

block content

block top-menu

This is my layout.jade: 这是我的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

This is my top-menu.jade: 这是我的top-menu.jade:

extends index

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

How can I have my menu show up when I use res.render('index'); 使用res.render('index');如何显示菜单res.render('index'); ? Or am I just understanding jade inheritance wrong? 还是我只是理解翡翠的继承是错误的?

I'm using this site for understanding: http://www.learnjade.com/tour/template-inheritance/ 我正在使用此网站进行了解: http : //www.learnjade.com/tour/template-inheritance/

You would actually have to use res.render('top-menu') for this to work as you have it set up. 实际上,您必须使用res.render('top-menu')进行设置。 I would suggest using include to bring top-menu into your layout. 我建议使用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

Note: you will need to move top-menu above content if you want it to actually show up above the content. 注意:如果要使顶部菜单实际显示在内容上方,则需要将其移至内容上方。

Then you don't have to extend anything in your top-menu nor do you have to declare a block to override because it will just be included in the layout. 然后,您不必在顶层菜单中扩展任何内容,也不必声明要覆盖的块,因为它只会包含在布局中。

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

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

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