Html react路由器链路包裹div后台不';我没有出现
刚刚react router出现了一个有线问题,当我在其中包装一个带有背景的div时,它不会显示图像,但是如果我注释掉链接,背景会显示出来,有人遇到过同样的问题吗Html react路由器链路包裹div后台不';我没有出现,html,css,reactjs,react-router,react-router-dom,Html,Css,Reactjs,React Router,React Router Dom,刚刚react router出现了一个有线问题,当我在其中包装一个带有背景的div时,它不会显示图像,但是如果我注释掉链接,背景会显示出来,有人遇到过同样的问题吗 <Link to={{ pathname: "/productDetail", search: "?productId=" + props.product.productid }}>
<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;
}
sass文件:
.image{
宽度:100%;
身高:100%;
背景色:白色;
背景尺寸:包含;
背景重复:无重复;
背景位置:中心;
边缘底部: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;
}
sass文件:
链接{
文字装饰:无;
宽度:100%;
身高:100%;
.image{
宽度:继承;
身高:继承;
背景色:白色;
背景尺寸:包含;
背景重复:无重复;
背景位置:中心;
边缘底部:5px;
}
这就是定义和设置高度的方法
<div
style={{
backgroundImage:`url('https://images-eu.ssl-images-amazon.com/images/I/41lMD31ltzL.jpg')`,
height:'500px'}}>
</div>
这样定义
<div
style={{backgroundImage:`url(${myUrl})`,
height:'500px'}}>
</div>
谢谢你的回复,我终于明白了,这是因为我的SASS文件,当我添加链接时,SASS结构发生了变化,因此我为div设置的宽度和高度无法工作。
<div
style={{backgroundImage:`url(${myUrl})`,
height:'500px'}}>
</div>