Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use create-react-app to develop multiple pages?

Tags:

reactjs

When creating an app with create-react-app,there is only one index.html,does that means React can only handle one SPA at a time? What if I want to develop multiple pages? Should I create another SPA with create-react-app and then put them together after building each of them?

like image 458
Gustaf Zhang Avatar asked Sep 01 '17 10:09

Gustaf Zhang


People also ask

Can I create multi page application in react?

The use cases for having multiple pages in a single React app are pretty simple. You can create a website, and easily classify different types of content on different pages. But, it should also be understood that the default implementation of React is made to use a single HTML file, and this is by design.

Is react single page app or multi page?

React is great for single page applications because it allows developers to create applications that are mobile first and responsive. React allows developers to create applications that are fast and easy to update, which is great for mobile applications.

Is create-react-app good for production?

create-react-app is a generic framework that need to account for several scenarios. Trimming your build after an eject may be a daunting task. For production apps that will grow, I will not recommend going the create-react-app route. Start with a basic build environment with webpack.


1 Answers

Update:

Parceljs can do that. here is docs.

You can use Parcel instead of Webpack (which being used in create-react-app) and it provide you zero config environment to develop web apps (using react or anything else).


Having multiple pages (instead of SPA) is not what most React environments had in mind [before - see update above].

You can have different page URL's using react-router or similar client side routing solutions.

If the concern is bundle size, there are solutions using webpack or parcel to lazy load each bundle whenever they needed or cache bundle (using service workers) and so on (Tree shaking, ...). (check Code Splitting in React Docs)

Other concern I might have in my brain is SEO, in this case you may find Isomorphic app (react server side rendering) useful which initialize first view of requested URL HTML and sends it to client, then client will load react and react will take control of UI. This will help Google (or other search engines) find your URLs fast and user experience in transitions between pages will remain seamless.

like image 141
Developia Avatar answered Oct 14 '22 17:10

Developia