简体   繁体   English

将一个值附加到 reactjs 中的现有 url

[英]append a value to existing url in reactjs

I have the following url and a parameter :我有以下网址和一个参数:

number:200
"http://localhost:8000/textpath"

I want the path to be like this:我希望路径是这样的:

"http://localhost:8000/textpath/200"

How do I do that using Reactjs?I want to use the appended url in fetch method as follows:我如何使用 Reactjs 做到这一点?我想在 fetch 方法中使用附加的 url,如下所示:

fetch("http://localhost:8000/textpath/200")

Try using Template literals.尝试使用模板文字。

const url = `http://localhost:8000/textpath/${number}`    
fetch(url);

where number = 200其中数字 = 200

Refer here for more information请参阅此处了解更多信息

一个简单的附加就完成了工作。不必复杂化

fetch("http://localhost:8000/textpath/"+number)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM