'How to run React Project w/ Router on Xampp

I tried to create a fresh new react-webpack-redux (yeoman generator) project and there something I notice with routing when running compiled project on xampp w/c I don't have idea how to solve.

First scenario: Without Router Compilation. Compiled using npm run dist. Copied the files from dist folder and placed in my htdocs in my public server (using xampp).

enter image description here It works fine. Also works fine in my local Drive C:

Second scenario: With Router Compilation. Now when I use React-Router. (here is my code)

Code with router

It worked of course on webpack dev localhost:8000 w/ the command npm run serve.

enter image description here

But when I compile to production. npm run dist and then same thing copy the files from /dist folder and place in my public server (same as the first scenario - using xampp) inside htdocs folder.

enter image description here

It won't run.

Am I missing something when using Routes? Or do i need to configure something in my public server (I'm using xampp).

I hope you can help me on this.

Thank you.



Solution 1:[1]

If you creat app with react-create-app just build your project with npm run build. then copy folder build to htdocs.run on on browser localhost/projectname.

if your page is blank just edit path of some including file in index.html. when I run with npm run build sometimes its create wrong path including file. its work for me when I edit index.html before

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rafles Nainggolan