2

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?

user2127480
  • 4,623
  • 5
  • 19
  • 17

2 Answers2

2

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.

hugomg
  • 68,213
  • 24
  • 160
  • 246
0

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(''));
Community
  • 1
  • 1
plalx
  • 42,889
  • 6
  • 74
  • 90