Search code examples
reactjsgithub-pages

Github Pages requesting wrong url when deploying react app


After publishing my react app, I noticed the page was blank, after going to the network tab on inspect, I realized Github pages was requesting:

/assets/index-1acd6362.js

instead of:

/project-name/assets/index-1acd6362.js

My package.json already has the correct url on the homepage field.

https://github.com/migars123/react-league-champs

https://migars123.github.io/react-league-champs/


Solution

  • homepage in package.json is for create-react-app

    For vite you need to set base in vite config to your github repo name

    import { defineConfig } from 'vite'
    import react from '@vitejs/plugin-react'
    
    // https://vitejs.dev/config/
    export default defineConfig({
      plugins: [react()],
      base: '/react-league-champs/'
    })