How To Add Robots.Txt To Next.Js Application
In this article you will learn about how you can add robots.txt file to your next js app
framework offers a lot of interesting alternatives to interest developers, whether it’s the way it creates pages (statically or on server request) or changes them with IncrementalStatic
Regeneration. One of the key advantages of Next.js over other frameworks such as Create React App is its SEO support, which stands out among all of its capabilities.Next.js has a variety of useful features. This
React is a great language for JavaScript developers, but it’s terrible for SEO
. The reason behind this is because React is rendered on the client side. When a user requests a page, instead of sending HTML, the server delivers JavaScript, which the browser then uses to generate the page.
As a result, the first page load time in an SPA (Single page development)
is often longer than in a server-side rendered application. Furthermore, Google bots did not correctly crawl JavaScript for a long period.
Next.js addressed this issue by not only being based on React, but also by providing developers with server-side rendering. This improved the migration of developers’ apps.
A robots.txt
file on your website is important for SEO. This post will explain what a robots.txt
file is and how to add one to your Next.js application, which Next does not do by default.
Adding A Robots.Txt File To Your Next.Js Application.
Before, you had to create a server.js
file and a new path that pointed to the robots.txt
file. But not in the most recent version! In the latest version of Next.JS, you can place your robots.txt file in the public directory. The public directory is intended to replace the static directory.
Everything in the public directory will be visible at the root domain level. So, instead of /public/robots.txt
, the URL for the robots.txt file would be /robots.txt
.
If you want to learn more about how to add a robot.txt file in next.js then visit our blog for a step-by-step explanation.