【发布时间】:2020-05-06 01:18:56
【问题描述】:
刚遇到 react-router <Link> 的有线问题,当我在其中包装带有背景的 div 时,它不显示图像,但如果我注释掉链接,背景可以显示,有人吗遇到同样的问题?
<Link to={{
pathname: "/productDetail",
search: "?productId=" + props.product.productid
}}>
<div
className="image"
style={{
backgroundImage: `url(correctURL)`
}}
/>
</Link>
网址是正确的,我可以保证当我注释掉链接时它可以正常工作。
更新: 不工作的一个:
<Link to={{
pathname: "/productDetail",
search: "?productId=" + props.product.productid
}}>
<div
className="image"
style={{
backgroundImage: `url(correctURL)`
}}
/>
</Link>
sass file:
.image {
width:100%;
height: 100%;
background-color: white;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
margin-bottom: 5px;
}
这是我的解决方案:
<Link className="link" to={{
pathname: "/productDetail",
search: "?productId=" + props.product.productid
}}>
<div
className="image"
style={{
backgroundImage: `url(correctURL)`
}}
/>
</Link>
sass file:
link {
text-decoration: none;
width: 100%;
height: 100%;
.image {
width:inherit;
height: inherit;
background-color: white;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
margin-bottom: 5px;
}
【问题讨论】:
标签: html css reactjs react-router react-router-dom