0

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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

I know --save but what is --save-deps?
Sorry, I was thinking of --save-dev but --save is probably best. updated answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.