Update the template file so the body looks like so:\n \n \n\nNext, we\u2019ll define the routes we want our app to have using React Router. We can pass a value into our view when we render it, and then use EJS syntax to tell it to output that data. Our server will figure out what HTML it needs to render, and pass that into the view. This will demonstrate how to use React Router on the server side to make sure our React app plays nicely with URLs.\nFirstly, let\u2019s update views/index.ejs. Our app will have two routes, / and /about which will both show a small amount of content. Run this command:\n./node_modules/.bin/babel-node server.js\nAnd you should now be able to visit and see \u2018Hello World\u2019 right there:\n\nBuilding the React app\nNow we\u2019ll build the React application entirely on the server, before adding the client-side JavaScript right at the end. Because we installed babel-cli earlier we have access to the babel-node executable, which will transform all your code before running it through node. \n \n My App\n \n\n \n Hello World\n \n\nFinally, we\u2019re ready to run the server.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |