In this guide, we will walk you through the process of creating a sitemap for Next.js website hosted on Vercel. A sitemap is crucial for optimising your website’s search engine visibility, and we’ll provide you with the necessary steps to ensure your web pages are indexed effectively.
Step 1: Install the necessary dependencies
To generate a sitemap for Next.js website, start by installing the next-sitemap
package. Open your terminal, navigate to your project directory, and run the following command:
npm install next-sitemap
Step 2: Configure your sitemap for next.js
Create a new file called next-sitemap.js
in the root directory of your Next.js project. Inside this file, configure your sitemap settings, including the siteUrl
and any additional customization options you require. For more details, refer to the next-sitemap
documentation.
Step 3: Generate the sitemap
In your package.json
file, add a script to generate the sitemap. Open the file and include the following script:
"scripts": {
"generate-sitemap": "next-sitemap --config=next-sitemap.js"
}
Save the file and run the following command in your terminal:
npm run generate-sitemap
This command will generate the sitemap for your Next.js website based on the configuration specified in next-sitemap.js
.
Step 4: Deploy the sitemap for next.js to Vercel
After generating the sitemap, it’s time to deploy it alongside your Next.js website on Vercel. Log in to your Vercel account, navigate to your project, and proceed to the “Settings” tab. Scroll down to the “Advanced” section and locate the “Build & Development Settings.” Add the following build command:
npm run generate-sitemap && next build
This command ensures that the sitemap is generated before building your Next.js project.
Step 5: Submit the sitemap to search engines
With the sitemap generated and deployed, it’s crucial to submit it to search engines for indexing. Log in to your Google Search Console account (or other search engine webmaster tools) and submit the URL of your sitemap. This helps search engines discover and index your website’s pages more effectively.
Conclusion:
Creating a sitemap for a Next.js website hosted on Vercel is a vital step in optimizing search engine visibility. By following this step-by-step guide, you can generate a sitemap, deploy it on Vercel, and ensure that your web pages are easily discoverable and indexed by search engines. Improve your website’s SEO and enhance its overall performance by implementing this essential sitemap feature.
Remember to regularly update and regenerate your sitemap whenever you add or remove pages from your Next.js website to keep it accurate and up-to-date.
Click here to get started with vercel.
For more programming topics, click here.