I have a simple task.
I have a header which loads few a
links.
<a class="nav-link" href="menu">Menu 1</a>
I am trying to load the url /menu
from the link.
My app.js
file
app.use('/', index);
app.use('/menu', index);
My index.js
file
/* 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
. It still stays on the index
page.
Just asking, any issues with the app.engine
settings?
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:
defaultLayout: 'index'
And try remove
app.use('/menu', index);
is superfluous here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.