Republic is a library for React that gives you universal routing, forms, and actions. It currently is built to work with Express + Next.js but has been built in mind that these may not always be the stack of choice.
If you miss the days of Rails forms and controllers, you'll love Republic.
We have a lovely document for creating an application from scratch using Express + Next.js + Republic. The guide is a complete walkthrough that's ideal for first time users. Read it to get started.
If you are familiar with Republic or you're just feeling brave you can use this quick start instead of the getting started guide. It's particularly ideal if you need a check list for adding Republic to your new application.
Use Next.js's example of custom server using Express to setup your app ready to install Republic.
app.js file in the root of your application, or any where else, just remember to adjust the path when copying examples.
Create a Next.js page in a directory that matches the action. For example with an action of 'blog#index' you should place your page in
You need to make sure you wrap your page with
That's your page setup.
Install republic first with:
npm install --save republic
Now add two middleware to your Express setup. The following code adds parsing for POST data.
// Handle POST dataserver
And then we add republic into the mix:
// Hook up upcoming + express + nextserver
Make sure the path to your app file is correct.
Now you should be able to run the app and visit
/blog or whatever your URL was.
To be completed...
Nice to haves: