I am trying to create a meta tag handlebars helper that grabs the url pathname and uses that value for a switch statement which will then return the string to my meta tag in HTML head, but I am not sure the best way to currently grab the url path for my switch statement. I tried window.location.pathname
, but get an error that window
is not defined. I know that the path module requires you to pass something to it to parse out, but I'm not sure what the best value would be for that. Can anyone help me?
Here is my handlebars helper file:
var path = require('path');
var metaHelpers = function(hbs) {
hbs.registerHelper('metaTitle', function(){
var urlPath = path.dirname();
console.log(urlPath);
switch(urlPath) {
case "/": {
return 'Index Test'
}
break;
case "/login": {
return 'Login Test'
}
break;
default: {
return 'No Meta Tag'
}
}
});
};
module.exports = metaHelpers;
req.originalUrl
but receivedCannot read property 'originalUrl' of undefined
– cphill