问题描述
我的角度应用程序中有一个拦截器,其中对特定的GET请求禁用了加载微调器。直到现在,我一直没有麻烦,直到必须添加带有路径变量的URL。我不知道如何使用Regex捕获路径变量。以下是基本的代码段:
@Injectable()
export class LoadingScreenInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>,next: HttpHandler): Observable<HttpEvent<any>> {
let displayLoadingScreen = true;
for (const skippUrl of this.skippUrls) {
if (new RegExp(skippUrl).test(request.url)) {
displayLoadingScreen = false;
break;
}
}
...
必须跳过的网址:
skippUrls = [
'/product/images','/product/${productId}/image',// Stuck on this one. Simply copy pasting the url string doesn't seem to work
'/category/',...
谢谢您的帮助!
解决方法
尝试此正则表达式:
'\/product\/.*\/(image)$'