I'm trying to put together a regex router that includes an arbitrary number of slugs and key-values.
I'm doing this by creating an object of patterns and their respective modules and will then match the regex to the module.
But JavaScript throws an error when I use the "+" operator to concatenate strings inside of the object definition.
// URI PATTERNS
var SLUG ='\/[a-z|A-Z|0-9|-]+)([\/]{0,1})?';
var KEYS ='\/?(\?.*)?$/';
// ROUTES
var routes = {
'\/public\/images' + KEYS : 'images', /* <-- ERROR: '+' Unexpected token */
'\/public\/other' + SLUG + KEYS : 'something-else',
};
Why is this error being thrown and how can I concatenate these values outside of storing them in separate variables?
[ ]to add property values then . Like just have a routes plain object likeroutes= {}then you can doroutes[ your concatenation logic] = 'images';