spa-github-pages icon indicating copy to clipboard operation
spa-github-pages copied to clipboard

Mention alternative of `HashRouter`

Open deantork-sc opened this issue 2 years ago • 5 comments

I was having problems with my SPA in Github Pages, and found a few solutions to the problem. This project fixes the problem in a roundabout way, and a slightly more direct solution is using HashRouter instead of BrowserRouter. I don't know if this fixes all instances of this problem, but it worked for me.

I think the readme should mention this alternative for folks who want a more lightweight solution.

deantork-sc avatar Jan 03 '23 15:01 deantork-sc

@deantork-sc, thanks, for me it worked as well!

gatinhap avatar Mar 21 '23 10:03 gatinhap

Do you have examples of how to achieve this? @deantork-sc @gatinhap

lucharo avatar Apr 16 '23 12:04 lucharo

@lucharo - you can have a look into my repo where I use it - https://github.com/gatinhap/magdak and the specific file - https://github.com/gatinhap/magdak/blob/main/src/main.jsx. Instead of wrapping my <App/> in BrowserRouter, I wrapped it in HashRouter and that's all :)

gatinhap avatar Apr 17 '23 13:04 gatinhap

Thanks for the reply I made it work in the end. I was confused at the fact I couldn't serve my builds folder with serve -s build when my package.json included my GitHub pages url as the homepage field but then I realised despite that the site does build correctly in gh pages itself 🎉 https://luischaves.xyz/recipe-portfolio https://github.com/lucharo/recipe-portfolio

lucharo avatar Apr 28 '23 10:04 lucharo

Agree that this should be mentioned as an alternative.

However, I wanted to add that I came here from my HashRouter implementation, since I wanted more shareable links (without the /#/ prefixing all my routes).

stxgao avatar Oct 29 '23 02:10 stxgao