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,473
  • 5
  • 18
  • 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
  • 66,048
  • 22
  • 153
  • 240
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
  • 41,415
  • 5
  • 69
  • 87