app.js
var exphbs = require('express-handlebars');
app.engine('handlebars', exphbs({defaultLayout: 'layout'}));
app.set('view engine', 'handlebars');
app.use('/catalog', require('./routes/catalog'));
so in my routes folder I have a folder call catalog then within it I have catalog.js.
In catalog.js I do
var express = require('express');
var router = module.exports = express.Router();
router.get('/', function(req, res) {
res.render('catalog/index');
});
It worked fine when I go to http://localhost:3000/catalog
but it excluded from the layout when I try to run http://localhost:3000/catalog/
Any idea why?
There is an npm package (connect-slashes) which installs some middleware which will add a slash on urls without one. This process is called URL canonicalisation.
This is better because you won't display similar content for 'catalog' and 'catalog/' urls which would be bad for SEO (duplicate content penalties).
Package details here:
https://www.npmjs.com/package/connect-slashes
From the command line:
npm install connect-slashes --save
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.