typescriptt“ ”;不工作,我怎么能使用一个反斜杠

typescriptt "" not working, how i can use one backslash?

本文关键字:一个 工作 怎么能 typescriptt      更新时间:2023-09-26

我在Typescript上有一个小问题,为什么我只能使用一个反斜杠?

我想要这样的url: "'/hello'/"+ urlRoute + "'/([0-9]*)"

当我这样做时,我只有"/hello/"+ urlRoute + "/([0-9]*)"

但是如果我做这个"''/hello''/"+ urlRoute + "''/([0-9]*)"

字符串是"''/hello''/"+ urlRoute + "''/([0-9]*)"

我尝试了一些解决方案,但没有工作,我总是有两个/三个反斜杠,但从来没有一个^^

如果有人能帮我,由于

Protip使用模板字符串:https://basarat.gitbooks.io/typescript/content/docs/template-strings.html

也就是说你的代码工作得很好,例如

let urlRoute = "something"; 
console.log("'/hello'/"+ urlRoute + "'/([0-9]*)" == `/hello/something/([0-9]*)`); // prints true