user29603865
user29603865

Reputation: 1

React Asset Not Loading from public or src Directory

I deployed my portfolio using gh-pages and all my assets are not showing

I'm having trouble displaying an svg,png,JPG jpeg assets in my React project. I initially placed the file in src/assets/Leo.svg, but it didn't load. I then moved the entire assets folder to public/assets/Leo.svg, but it's still not appearing.

Strangely, the same Leo.svg file works when used as the browser tab logo (favicon), but it does not display in the navbar.

What I Tried:

  1. Using an import statement when the file was in src:

   import hauAccreditationStatus from "./src/assets/hauAccreditationStatus.jpeg";
   const projects = [
    {
      title: "HAU School Department Accreditation Status",
      category: ["graphic-design"],
      image: hauAccreditationStatus,
      tech: ["Canva"],
    },

  1. Moving the entire assets folder to public/ and referencing it directly:

    const projects = [
     {
       title: "HAU School Department Accreditation Status",
       category: ["graphic-design"],
       image: "/assets/hauAccreditationStatus.jpeg",
       tech: ["Canva"],
     },
    
    • The image does not display in the browser.
  2. Using the full path with the repository name (since it's deployed on GitHub Pages):

    <img src="/Leo_Portfolio/assets/hauAccreditationStatus.jpeg" alt="HAU Accreditation Status" />
    
    • Still no luck.

Additional Details:

Expected Outcome: The assets should be displayed in the browser.

Question: What is the correct way to reference the image so that it loads both in development and when deployed on GitHub Pages?

Upvotes: -1

Views: 22

Answers (0)

Related Questions