Our React site renders a game that we built in HTML and JS (not very elegant, but it’s what we could do with our skills and time). When it’s hosted locally, it works fine. But on Netlify, if you refresh the game page, it only renders the HTML and JS. This means all of the React stuff (nav bar, high score, even CSS) is gone, and the game is all but unplayable.
We’ve tried making the game refresh itself, but that doesn’t work. Tried searching the forums and asking the AI, neither one seemed to help me.
@ScottCPetty This is occurring because your React based main site is a Single Page Application (SPA), and you’re encountering additional confusion because you also have a separate game.html file.
So while your site has a /login page, it does not have a /login.html page.
The issue with your /game page is the same, except your site does have a /game.html page.
Your /public/game.html file will be getting output as /game.html
When the browser makes an actual request to /game it will be given that file.
That file does not contain any of the React logic, so that’s why none of it displays.
I can’t advise precisely what you need to do with the game files themselves, as I’ve barely looked at them, but the main fix you’re looking for is in the documentation here:
Adding that would ensure that a request for /login is returned the contents for your /index.html file, which in turn will handle the /login route and display the appropriate content.
In the case of your /game route, you would need to ensure there is no /game.html file, otherwise that would take precedence and be served instead of the rewrite.
You could remove it if it’s unnecessary, or otherwise rename it so the paths do not collide.
Aaah, thank you. I didn’t know Netlify worked that way with React apps. I changed the file names for the game’s HTML and JS, and then added the _redirects file. Just in time for the deadline too, lol. Thanks again.