P粉5093831502023-08-22 00:48:37
In create-react-app
, it seems that you cannot use relative paths to reference images. Instead, you can use import to bring in images:
import logo from './logo.png' // 图片的相对路径 class Nav extends Component { render() { return ( <img src={logo} alt={"logo"}/> ) } }
P粉4781887862023-08-22 00:46:47
You are using a relative URL, which is relative to the current URL rather than the file system. You can solve this problem by using absolute URL
<img src ="http://localhost:3000/details/img/myImage.png" />
However, this is not ideal when you deploy to www.my-domain.bike or any other site. A better approach is to use a URL relative to the site root
<img src="/details/img/myImage.png" />