Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do server side rendering with Laravel + React.js + Redux?

We are setting an app using Laravel in backend and React.JS + Redux in front end. So looking for solution for server side rendering (for SEO).

Found this solution: https://github.com/tz5514/Laravel-Redux-Isomorphic but it seems like in backend it using express.js to render.

So I am searching for any better server side rendering solution.

like image 734
Vivek Sancheti Avatar asked Apr 02 '16 09:04

Vivek Sancheti


2 Answers

React is javascript, so it needs a javascript engine in order to run, so one way to see a laravel project is to think of it as the 'backend' api server, which is completely separated from the 'frontend' server which uses node to run the javascript part of the application.

In other words, you have two apps, the one with laravel that exposes an api which could be used by any other service in the infrastructure, and the reactjs app which is a nodejs app that consumes that api, and handles the magic of react + redux.

The way your site is actually accessed from the outside world is thru the express/nodejs app, which calls the laravel api for data persistence and other business logic.

The laravel app handles sessions, oauth, the database, file access to the hardrive and so on, while the nodejs app handles the actual website routing, the templates, the css and javascript part.

I got this answer from HashNode

like image 109
Vivek Sancheti Avatar answered Sep 19 '22 00:09

Vivek Sancheti


you can use the spatie/laravel-server-side-rendering package, it is great for both React & Vue. Here you can find YT tutorial for this package usage as well - https://youtu.be/uO42Kpa4pvI

like image 42
devsourav Avatar answered Sep 19 '22 00:09

devsourav