简体   繁体   中英

Creating react and express application

Hry there I'm building an application with React on the client side and expressJS on the server side. I'm kinda new to react and have some question about it -

  1. I understood that react Route can navigate the user to the matched component. But let say that I want to navigate the user via express routing functions and also to perform some authentication there. what should my server return? the main HTML file? or the App.js? If one has some good tutorial about this issue it will be great.

Let say your React App starts. So you have a standalone application run in the browser. Your backend should only send data to your front end. It should not interfere directly into the front end! Your frontend reacts independently according to the data it gets from the backend.

So if a user wants to access content to which he has no authorization, the backend should return the status code 401. Your frontend should evaluate this response and show the user a suitable message.

You should look at your frontend and baking separately from each other. Your backend can deliver your frontend to the browser and provide an API for its queries. But it does not have to be mandatory.
You can write a twitter app with react. So your backend would only deliver your static files (your react app). All inquiries of your front end would go to the twitter api.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM