How to implement angular server side rendering in laravel?
I created a single page application with angular 5. I use this application with laravel backend. In the laravel project I have an angular folder, this folder store all the angular files. I built the angular application outside the angular folder, in a public folder in the root laravel's project folder. I set the web.php file, so if I go to homestead.test url the index.html will loaded from the public folder. After I set up the serverside rendering with stories universal rendering, I built the client application and the server bundle. After I did this, and go to the homestead.test in the browser a I saw that my application doesn't look like before. With normal ng build (I'm hungarian by the way, so I used hungarian words): After i did the universan rendering builds (ng build --prod --extract-css, ng build --prod --extract-css --app 1 --output-hashing=false, I used the --extract-css, because I used scss in the angular and when i didn't used it i got a lot of warnings): And when I looked at the page source, it looked like the original angular source, but in the express server the source shows the real content. So my question is how to set up laravel to act like the express server? The ng build --prod --extract-css create a lot of js file, the assets folder and some other files, but the ng build only create some of them, without the assets folder. So how can I import all the assets folder and the js files in laravel? The stories universal rendering create a server.js file too from Node server.ts. I don't know this file is necessary in laravel.
I also got some addicitonal questions: Is it the best way to connect laravel to an angular application? If yes, can I host it with real web host? Is there any free web host to test my application? If I succesfully display the angular app in laravel like I did with express server, than refresh the page in any url will works? Because now I got an error message.
I created this application as a thesis app for my university and I've neved host app in the web, I only used local hosts.
The idea of Angular Universal is to run the javascript on the server side to generate the page on the server side. Of course that is easy with Node (Express JS) and hence that is there already.
Regarding Angular Universal on PHP, you can follow this Github issue. What I understand is, at least today, there is no support. But it's true that many people want to have the support and probably the support will be there in future.
For the time being, you have the following options:
Both the options are used depending on the requirement. For a larger microservices based architecture the second approach is preferred as it makes the lifecycle of the UI part and the API part independent.
However, for smaller projects where the user base is less and you don't really care about SEO, the first option makes sense.
链接地址: http://www.djcxy.com/p/31398.html