0

I have an angular project hosted in GitHub pages which has a total of five routed links. When I load the website for the first time, it works perfectly fine and I can navigate through all these five links. However, trouble starts when I refresh in any of the route, even if it is the index/home route. What I noticed by enabling network tab while trying to debug is that on first load my js and css file points to https://nayan-jyoti.github.io/praktanchatrabharati-ssvnk/****.js while on refresh, it points to https://nayan-jyoti.github.io/****.js and throws 404 error.

Can someone help me what's wrong here?

Nayan J
  • 27
  • 9
  • Does this answer your question? [GitHub pages are not updating](https://stackoverflow.com/questions/20422279/github-pages-are-not-updating) – James Risner Mar 05 '23 at 20:55
  • No. I checked that Q before posting. My page was up and running fine. I just did some changes recently. Same was pushed but changes were not reflected. After some attempts, I deleted the whole gh-pages branch and rebuild everything. Do note, I have to edit my index.html always to change the tag value to href = "\my-repo-name\" and then resources path in main.xxxxxxxx.js as well, only then website loads and so the images, custom font etc. However, on refreshing, the issue appears as mentioned. – Nayan J Mar 06 '23 at 16:34

1 Answers1

1

This will probably fix your problem. Edit your app-routing.module.ts and make sure useHash is set to true:

@NgModule({
  imports: [RouterModule.forRoot(routes, { useHash: true })],
  exports: [RouterModule]
})
Rick
  • 1,710
  • 8
  • 17
  • Excellent. Worked! Thanks. By the way, can you briefly explain why was this required? – Nayan J Mar 07 '23 at 15:05
  • I have no idea and as far as I can tell, it should be defaulted to true, but for some reason it's not. I ran into this issue a couple of years ago and that was the solution I found. – Rick Mar 07 '23 at 15:45