Problems with Phaser 3 and React Router

Trying to use React Router to load the game onto the page, and encountering a strange issue. When you first go to the route the game is located, it works fine. However, if you follow a different route and then navigate back to the game route, the game won’t create the canvas.

the way I have it set up is this: the react game component is a div with a unique ID. Using “useEffect” with an empty array, I have it load in the script that creates the Phaser 3 game as an element (I can’t load them in together, or It won’t append to the div). When the route is first followed it works fine, but when you navigate back to other route, despite it still loading the script and appending it to the body as before, the script that creates the canvas for the game won’t load

Any ideas how I could fix this?

1 Like