当前位置:网站首页>记一个 nest.js 路由匹配后面所有路径问题
记一个 nest.js 路由匹配后面所有路径问题
2022-08-09 05:43:00 【crayon-shin-chan】
1.简介
一般路径参数只能匹配一个部分,只能匹配/view/aaa,不能匹配 /view/aaa/bbb
@Public()
@Get('/view/:path')
async pdfPreview(@Param('path') path: string, @Res() res: Response) {
this.logger.log('view pdf '+path)
await this.ticketService.getPdfStream('/'+path, res);
}
2.解决
如果想要匹配后面所有路径,需要用正则表达式来指定路径参数的匹配
@Public()
@Get('/view/:path(*)')
async pdfPreview(@Param('path') path: string, @Res() res: Response) {
this.logger.log('view pdf '+path)
await this.ticketService.getPdfStream('/'+path, res);
}
边栏推荐
猜你喜欢
随机推荐
牛客每日刷题之链表
顺 序 表
flask——介绍、安装、快速使用、配置文件、路由系统、视图
在命令行打开LaTeX宏包手册
华为鲲鹏生态培训试题
cglib获取不到接口注解
P8462 「REOI-1」奶油蛋糕
【深度学习】聊一聊什么是卷积神经网络,卷积是什么意思?
STM32的Cube学习笔记(ADC)
获取开发版安全码SHA1时遇到的报错
Webgis地图框架的对比
条件编译
Distributed timing task framework xxl-job source code analysis
Functions and differences of command, shell, raw, script modules, application of file, copy, fetch, synchronize
shell函数、数组
A day to learn a public company: Sophia
【LeetCode】761.特殊的二进制序列
22-08-08 西安 尚医通(04)MongoDB命令、MongoTemplate、MongoRepository
Still don't know what business intelligence (BI) is?After reading this article, you will understand
MATLAB图像处理入门