is developed by create-react-app, and there is a nested route, such as
like home/music. on the home page, the picture can be displayed, and the request address is correct static/media/
, but under home/music, a home, is added to the path in front of the image to become home/static/media/
my nested route looks like this
<Route path="/home" exact component={FindMusic} />
<Route path="/home/fmusic" exact component={FindMusic} />
<Route path="/home/fradio" exact component={RadioPage} />
I wonder if it is written in this way?
the main route is written as follows:
<Switch>
<Route path="/home" component={AsyncHome} ></Route>
<Route path="/video" component={AsyncVideo} ></Route>
<Route path="/mymusic" component={AsyncMyMusic} ></Route>
<Route path="/friends" component={AsyncMyFriends} ></Route>
<Route path="/user" component={AsyncUser} ></Route>
</Switch>
the path of the picture is written like this:
import daypushbtn from "./images/daypushbtn.svg"
import fmbtn from "./images/fmbtn.svg"
import musiclistbtn from "./images/musiclistbtn.svg"
import rankbtn from "./images/rankbtn.svg"
const switchImg = (e) =>
{
switch (e.props.name) {
case "FM":
return fmbtn
break;
case "":
return daypushbtn
break;
case "":
return musiclistbtn
break;
case "":
return rankbtn
break;
}
}
export class DayPushItem extends Component {
render() {
return (
<div className="DayPushItem">
<div className="itemImg">
<img src={switchImg(this)}/>
</div>
<div className="itemText">{this.props.name}</div>
</div>
)
}
}
export default DayPushItem
online address: http://react.packy.club/ is idle to learn react and wants to imitate a NetEase music
Sorry, I read it wrong. The address of the picture has not changed. But the address cannot be requested, as shown in the following figure:
Private FM. The picture in the daily recommendation, playlist and ranking is wrong.
main domain name home/
home/fmusic
:
:
is this because the relative path is used when the picture is introduced? But when my create-react-app writes an alias, build will make an error.
my react-route uses BrowserRouter and apache server, so A. htaccess is configured in the project root directory so that the project refresh will not be 404.