reactjs - create-react-app Server Side Rendering -
i trying achieve server side rendering create-react-app project. don't need routes because it's single-page application. have been going through articles seem quite complicated me. guide me how or link me simpler articles please?
here code till now:-
the main app component, imports other components:-
import react, { component } "react"; import homepage "./homepage"; import "./app.css"; class app extends component { render() { return( <div> <homepage/> </div> ); } } export default app;
the express code till now:-
import express "express"; import react "react"; import { rendertostring } "react-dom/server"; import app "../src/app"; const app = express(); app.use(express.static("../public")); app.get('*', (req, res) => { res.send(` <!doctype html> <head> <title>universal react</title> </head> <body> <div id="root">${rendertostring(<app/>)}</div> </body> </html> `); }); app.listen(3000, () => { console.log('server running on port 3000'); })
all articles or videos have checked out till use webpack , make changes webpack.config.js file using create-react-app comes webpack included, there no config file bit confused how make required changes?
you have eject project/scripts/webpack config
here's example article on how implement server-side rendering react-router/redux
wiki
Comments
Post a Comment