简体   繁体   English

res.render不会加载新页面

[英]res.render doesn't load new page

I have a simple task. 我有一个简单的任务。

I have a header which loads few a links. 我有几个加载一个头a环节。

<a class="nav-link" href="menu">Menu 1</a>

I am trying to load the url /menu from the link. 我正在尝试从链接加载url /menu

My app.js file 我的app.js文件

app.use('/', index);
app.use('/menu', index);

My index.js file 我的index.js文件

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


/* GET new page. */
router.get('/menu', function (req, res, next) {
  res.render('users', { title: 'New Page' });
});

The problem is it still loads the or rather refreshes the same page. 问题在于它仍加载或刷新同一页面。 I am unable to get the content from /menu . 我无法从/menu获取内容。 It still stays on the index page. 它仍然停留在index页面上。

Just asking, any issues with the app.engine settings? 只是问问, app.engine设置有任何问题吗?

app.engine('hbs', hbs({ extname: 'hbs', defaultLayout: 'index', layoutsDir: __dirname + '/views/' }));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');

Sorry I can not write a comment so I try to write an answer. 抱歉,我无法写评论,所以我尝试写一个答案。 Make sure that the 确保

./views/users.hbs

has a file. 有一个文件。 In the settings of the HBS, the default index is set: 在HBS的设置中,设置了默认索引:

defaultLayout: 'index'

And try remove 并尝试删除

app.use('/menu', index);

is superfluous here. 这里是多余的。

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

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