Reputation: 4731
Sometimes the routing path is too long so I want the path to display in multiple lines for readability.
I know the normally a multiple line string is written like this:
var str = 'hello \
world \
hi;
However, this doesn't work in express.js routing.
router.route('/:hello/ \
:world/ \
:hi').get(...);
But this works:
router.route('/:hello/:world/:hi').get(...);
Any ideas?
Upvotes: 2
Views: 318
Reputation: 43728
Another way of doing it would be to use Array.prototype.join
. It used to be faster than using the +
operator, however it seems this have changed with modern browsers. Still, perhaps you prefer ,
over +
for readability, but that's just a question of style at this point.
router.route([
'/:hello',
'/:world',
'/:hi'
].join(''));
Upvotes: 0
Reputation: 69954
I often see people use string concatenation for this kind of thing
router.route(
'/:hello'+
'/:world'+
'/:hi'
)
In fact, some JS compressors for client-side code even have special logic for concatenating these bbroken up strings into a big single-line string.
Upvotes: 2