有时路由路径太长,因此我希望路径以多行显示以便于阅读。
我知道通常多行字符串是这样写的:
var str = 'hello \
world \
hi;
但是,这在express.js路由中不起作用。
router.route('/:hello/ \
:world/ \
:hi').get(...);
但这有效:
router.route('/:hello/:world/:hi').get(...);
有什么想法吗?
最佳答案
我经常看到人们使用字符串连接来做这种事情
router.route(
'/:hello'+
'/:world'+
'/:hi'
)
事实上,一些客户端代码的 JS 压缩器甚至有特殊的逻辑来将这些分解的字符串连接成一个大的单行字符串。
关于javascript - 如何编写多线路径进行路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24622151/