Next js is a lightweight react js framework for static and server-rendered applications
- Zero Setup:
Automatic code splitting, filesystem based routing, hot code reloading and universal rendering
- Fully Extensible:
Complete control over Babel and Webpack. Customizable server, routing and next-plugins.
- Ready for Production
Optimized for a smaller build size, faster dev compilation and dozens of other improvements.
and add a script to your package.json like this:
After that, the file-system is the main API. Every .js file becomes a route that gets automatically processed and rendered.
You may also like - React.js Interview Questions
- Server-rendered by default
- Automatic code splitting for faster page loads
- Simple client-side routing (page based)
- Webpack-based dev environmet which supports Hot Module Replacement (HMR)
- Able to implement with Express or any other Node.js HTTP server
- Customizable with your own Babel and Webpack configurations
Next js is most popular framework for building:
- Server Rendered App
- Progressive Web Apps (PWA)
- Static Website
- SEO friendly Websites
- Desktop Website
You may also like - Redux Interview Questions
You can create page your page inside pages folder.
You can create page your custom error page by defining a _error.js in the pages folder.
It's depends. but next.js recommends getInitialProps is an async function and it can be used to retrieve data from anywhere.
getInitialProps receives a context object with has the following properties:
- pathname - path section of URL
- query - query string section of URL parsed as an object
- asPath -
Stringof the actual path (including the query) shows in the browser
- req - HTTP request object (server only)
- res - HTTP response object (server only)
- err - Error object if any error is encountered during the rendering
You may also like - Node.js Interview Questions