reactjs - 包含标签的 reactjs 组件加载了错误的 url
问题描述
我正在为我的网站提供服务example.org
,使用 reactjs 16.13.1 和 typescript 构建。
我有一个显示如下图像的组件:
<img alt={""} className={"person-image"} src={person.imageUrl}/>
JSON 对象来自person
后端。ImageUrl 是一个如下所示的 url https://example.org/api/data/24361/img.jpg
:. 图像通过 Spring Boot 控制器提供。
图像无法加载,因为由于某种原因它被重写为:https://example.org/example.org/api/data/24361/img.jpg
为什么会example.org
被重复?
我检查了从服务器返回的 JSON 并且 url 是正确的:https://example.org/api/data/24361/img.jpg
如果我将 url 复制粘贴到浏览器上,它会正确加载,所以这不是反向代理问题,或者似乎不是。
如果我在将 url 传递给之前将其记录在控制台上<img>
,则它是正确的。
我从外部域加载了一些其他图像,它们加载没有任何问题。
<img>
如果图像来自同一个域并且正在使用绝对 url,那么标签是否对 url 进行了某种重写?有什么我在监督的吗?
编辑:组件代码
interface PersonProps {
person: PersonData
clickable?: boolean
}
export function Person({person}: PersonProps) {
const actions = [
new Action(
<><FullscreenOutlined/> Full</>,
() => {
// opens wrong url https://example.org/example.org/api/data/24361/img.jpg
const win = window.open(person.imageUrl, '_blank');
win?.focus();
}
)
]
// prints https://example.org/api/data/24361/img.jpg
console.log(person.imageUrl)
return <Wrapper
actions={actions}>
{/* loads wrong url https://example.org/example.org/api/data/24361/img.jpg */}
<img alt={""} className={"person-image"} src={person.imageUrl}/>
<div className={"person-body"}>
{person.name}
</div>
</Wrapper>
}
解决方案
推荐阅读
- logback - 错误和信息日志级别的 logback smtpAppender 邮件
- php - 减少大量方法参数的最佳实践/约定
- python - PyQt5 对象的 SEGV_MAPERR
- excel - 在 Excel 2016 中覆盖表格数据时清除其他行
- c++ - L_LineRemoveBitmap 返回一个空 HRGN
- falcor - Falcor - 'get' 不再将引用作为叶值发出
- stripe-payments - Stripe 订阅的程序化运费和税费
- php - 是否有 Ajax 函数或获取交集值的方法
- webview - 如何在 Web 视图 Dialogflow 集成中启用按钮
- arrays - VBA 函数似乎返回一个数组,但我得到“类型不匹配:预期数组或用户定义类型”