SPA running inside PHP

Rehan1579

New member
Hi there!

I have created a very simple two pages SPA using React 18 & Vite. One page is Listview containing list items and the other page is a DetilView to show the details of the selected item.

I have deployed my react build to a server already, but instead of serving my app directly, I want to render my app inside PHP, I want to use PHP for SEO (can't use Next.js or any other SSR frameworks).

I want to achieve both SSR + SPA behavior with using PHP + React
Check below image, that's how I'm trying to do it. Icon & Titles are being loaded but whole page is empty even though React is being rendered!

Any help would be apricated!
 

Attachments

  • 1.png
    1.png
    29.8 KB · Views: 0
  • 2.png
    2.png
    4 KB · Views: 0
  1. Enable SSR in your React app using React 18's built-in SSR capabilities.
  2. Set up a PHP server to serve the initial HTML with the React content.
  3. Ensure the server-side rendered HTML matches the client-side React code to avoid hydration mismatches.
  4. Check routing, data fetching, and Vite configuration for any issues.
By following these steps, you can combine SEO benefits from SSR with the interactivity of a SPA using PHP and React.
 
Back
Top