2

I have been working with react-router-dom for quite a time but not faced this problem at all, everything working fine with the navbar image when I'm in the "/" root address but when I route to /student/view/:id the navbar image is not loading!

Here's the code!!

Main file code:

<Router>
  <div className="App">
    <Navbar />
    <Switch>
      <Route exact path="/" component={StudentCard} />
      <Route exact path="/student/view/:id" component={StudentView} />
    </Switch>
  </div>
</Router>

Navbar file code:

 <nav className="navbar navbar-expand-sm navbar-light bg-white">
  <div className="container">
    <Link className="navbar-brand" to="/">
      <img src="assets/images/administrator.png" height="50px" alt="admin" />
    </Link>
4
  • Is assets a folder in your public directory Commented Jan 11, 2021 at 8:41
  • yes it is in public folder Commented Jan 11, 2021 at 16:05
  • 1
    Try /assets/images/administrator.png, plus remember to check the network tab for more info about the error ( or weird behaviour ) Commented Jan 12, 2021 at 6:53
  • thank you very much now i know whats the problem because of you it was that "/" that causing problem, thanks for increasing my knowledge. Commented Jan 12, 2021 at 23:09

1 Answer 1

3

The solution is as simple as add / at the beginning of the link to the image:

Just change <img src="assets/images/administrator.png"

to <img src="/assets/images/administrator.png"

Original answer were posted in comments by @GayatriDipali, I've moved it to answer section just to make it more readable!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.