NextJs File Based Routing A Review
NextJs File Based Routing A Review
Volume 7 Issue 4, July-August 2023 Available Online: www.ijtsrd.com e-ISSN: 2456 – 6470
INTRODUCTION
As per the NextJs official website, it is a full-stack application. Hence, NextJs is also a React framework
React and React framework for Production. Let's dive for Production. Next.js introduces a file-based routing
into what each of these statements means. NextJs system that leverages the file system to create
brings a few key features—file-based routing, server- application routes. In contrast to traditional routing
side rendering, API integration, and static site systems where routes need to be defined manually,
generation. In a contemporary Js framework like Next.js automatically routes files under the pages
React, we must add a dependency like 'react-router' to directory, significantly simplifying the routing
get routing capability. NextJs supports this out-of-the- process.
box, eliminating the need for a routing package.
The file-based routing system deviates from most
NextJs also has a strong ability of "server-side
client-side routing libraries like react-router, which
rendering.” The pages are rendered at the server and
need an explicit definition of each route. Instead, it
not the client, so the initial load is quick without
uses a convention-over-configuration paradigm,
needing a loading state before the render. The ability
automatically establishing routes based on the file
to generate content on the server also helps with better
structure. Let us now discuss the important key feature
Search Engine Optimization since the Search engine
of NextJs (file-based routing).
crawlers see the content that the users see on the page.
Since all the content gets pre-rendered on the server, it A. Nested Routes
is beneficial to Optimize Search Engines (SSO). Consider a freshly created Next Js project. The
NextJs also offers API integration out-of-the-box, project structure consists of a “pages” folder at the
which helps integrate the backend services efficiently. root, as shown in Figure 1 below. The contents of
Due to these critical features, NextJs is a full-stack this folder will decide the routing of the application.
React framework. Also, the attributes we discussed We will have an “index.js” file at the root of this
are crucial to building a Production-ready React folder. This file renders the contents at the “/“ path.
Figure 3: NextJs nested routes structure using Figure 5: Using “next/router’ to access the
file dynamic route query param