how to serve plain js single page application on github pages?

the website gives error 404 upon reload when it path except https://username.github.io/projname/
it does all routing to my paths using navbar links


const router=(hrf)=>{
    history.replaceState(null,null,hrf)
}

export default router

the function below is giving router paths

item.addEventListener('click', (e) => {
            document.querySelectorAll('.linkbtn').forEach(el=>{
                el.style.backgroundColor=''
            })
            document.getElementById('projectbtn').style=''
            e.preventDefault()
            router(e.target.parentElement.href)
            component(e.target.id.slice(0,-3))
            item.style.backgroundColor='#f2f2f2'

        })

i was expecting github to serve index.html with index.js to be served at all paths just
rest is handled by js

type here