Building Universal Server Rendered Apps with React and Next.js 3.0

Building Universal Server Rendered Apps with React and Next.js 3.0

In this post we will give you information about Building Universal Server Rendered Apps with React and Next.js 3.0. Hear we will give you detail about Building Universal Server Rendered Apps with React and Next.js 3.0And how to use it also give you demo for it if it is necessary.

Next.js is a framework for quickly building universal (also called Isomorphic) server-rendered web apps with React. In this tutorial I’m going to get you started with Next.js to build an example demo app showing the essential concepts of server rendered React apps.

Building apps with Next.js is dead easy, you just create a pages directory and place React components in it. Next.js will take care of everything.

Now lets get started

Installing Next.js 2.0

You can install Next.js 2.0 via npm with:

npm install --save next react react-dom

Installing Next.js 3.0

Next.js 3.0 is still in beta, you can also install it via npm with:

npm install next@beta react react-dom --save

Adding NPM Scripts to package.json

Building apps with Next.js is a matter of using three commands:

nextnext buildnext start 

So lets add NPM scripts to trigger these commands:

“scripts”: { “dev”: “next”, “build”: “next build”, “start”: “next start” },

Adding Pages

To create pages you first need to create a pages directory:

mkdir pages 

Adding the Home Page

Create an index.js file inside pages folder and put this content in it:

import Link from 'next/link'export default () => (<div>            <Link href='/'><a>Home</a></Link> -            <Link href='/about'><a>About Me</a></Link> -             <Link href='/contact'><a>Contact</a></Link>              <br></br>            This is the home page</p></div>)

Adding the About Page

Next create an about.js file inside pages folder then put the following content:

import Link from 'next/link'export default () => (<div>            <Link href='/'><a>Home</a></Link> -            <Link href='/about'><a>About Me</a></Link> -             <Link href='/contact'><a>Contact</a></Link>              <br></br>            This is about page</p></div>)

Adding the Contact Page

Add contact.js file inside pages folder then put the following:

import Link from 'next/link'export default () => (<div>            <Link href='/'><a>Home</a></Link> -            <Link href='/about'><a>About Me</a></Link> -             <Link href='/contact'><a>Contact</a></Link>              <br></br>            This is the contact page</p></div>)

Now you can launch next with:

npm run dev 

Your app will be available from http://localhost:3000.

As you can see the names of files inside pages directory become the routes except for / which points to index.js


Hope this code and post will helped you for implement Building Universal Server Rendered Apps with React and Next.js 3.0. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US