<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hassan Mubarak</title>
    <description>The latest articles on DEV Community by Hassan Mubarak (@hassan_mubarak).</description>
    <link>https://dev.to/hassan_mubarak</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4048488%2Fd5ebb3c2-bae7-46fc-b459-169b0d641ff6.jpg</url>
      <title>DEV Community: Hassan Mubarak</title>
      <link>https://dev.to/hassan_mubarak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hassan_mubarak"/>
    <language>en</language>
    <item>
      <title>Soft 404 Errors in Next.js</title>
      <dc:creator>Hassan Mubarak</dc:creator>
      <pubDate>Mon, 27 Jul 2026 00:05:26 +0000</pubDate>
      <link>https://dev.to/hassan_mubarak/soft-404-errors-in-nextjs-2l2o</link>
      <guid>https://dev.to/hassan_mubarak/soft-404-errors-in-nextjs-2l2o</guid>
      <description>&lt;h2&gt;
  
  
  Soft 404 Errors in Next.js: What They Are and How to Fix Them
&lt;/h2&gt;

&lt;p&gt;By Hassan Mubarak&lt;/p&gt;

&lt;p&gt;If Google Search Console has ever flagged pages on your site under "Soft 404," it can be a confusing warning. The page loads fine in your browser. Nothing looks broken. So why is Google saying it's a 404?&lt;/p&gt;

&lt;p&gt;This guide explains what a soft 404 actually is, why it's worth fixing, and how to handle it in a Next.js application.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is a Soft 404?
&lt;/h2&gt;

&lt;p&gt;A normal 404 happens when a server tells the browser "this page doesn't exist" using an HTTP 404 status code. A &lt;strong&gt;soft 404&lt;/strong&gt; happens when a page that should be treated as missing instead returns a 200 OK status, the server's way of saying "this page is fine" even though the page has little or no real content.&lt;/p&gt;

&lt;p&gt;Search engines rely on status codes to understand what's actually on a site. When a broken or empty page reports itself as healthy, it creates a mismatch: the page exists in the index, but there's nothing meaningful for a visitor to find.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Soft 404s Happen in Next.js Specifically
&lt;/h2&gt;

&lt;p&gt;Next.js makes it easy to build pages that pull content dynamically — from a CMS, an API, or a database. That flexibility is also where soft 404s tend to creep in. A dynamic route like &lt;code&gt;/products/[slug]&lt;/code&gt; will render &lt;em&gt;something&lt;/em&gt; even if the requested product no longer exists, because the page component still runs and returns a 200 status by default. Unless you explicitly tell Next.js "this content is missing, treat it as not found," the page will render an empty or broken-looking state while technically reporting success.&lt;/p&gt;

&lt;p&gt;Common triggers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A CMS entry or database record gets deleted, but the route that renders it doesn't check whether the data actually came back.&lt;/li&gt;
&lt;li&gt;A dynamic page has a typo'd or outdated slug in its URL, and the page renders a blank or near-empty layout instead of erroring out.&lt;/li&gt;
&lt;li&gt;Old static routes are removed from the site's navigation but the files (or generated paths) still exist and continue to serve.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why It's Worth Fixing&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Search engines waste crawl budget.&lt;/strong&gt; Time spent re-crawling broken pages is time not spent indexing your real content.&lt;br&gt;
&lt;strong&gt;Your site looks less reliable to search engines.&lt;/strong&gt; A pattern of soft 404s can signal weak site health, which isn't a status you want attached to your domain.&lt;br&gt;
&lt;strong&gt;Visitors land on dead ends.&lt;/strong&gt; Someone clicking through from search results to an empty page is likely to bounce immediately, which hurts both user trust and engagement metrics.&lt;/p&gt;

&lt;p&gt;How to Fix Soft 404s in Next.js&lt;/p&gt;

&lt;p&gt;1 Explicitly trigger a "not found" state&lt;/p&gt;

&lt;p&gt;The core fix is making sure a missing resource actually returns a not-found response instead of quietly rendering an empty page.&lt;/p&gt;

&lt;p&gt;App Router: call &lt;code&gt;notFound()&lt;/code&gt; from &lt;code&gt;next/navigation&lt;/code&gt; inside your page component when the data you need isn't there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;notFound&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;next/navigation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ProductPage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getProduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;notFound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// renders app/not-found.js and returns a 404 status&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ProductDetails&lt;/span&gt; &lt;span class="na"&gt;product&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pages Router: return &lt;code&gt;notFound: true&lt;/code&gt; from &lt;code&gt;getStaticProps&lt;/code&gt; or &lt;code&gt;getServerSideProps&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getServerSideProps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getProduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;notFound&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both approaches tell Next.js to serve a real 404 status instead of a hollow 200.&lt;/p&gt;

&lt;p&gt;2 Build a proper custom 404 page&lt;/p&gt;

&lt;p&gt;A default 404 is fine functionally, but a custom one helps retain visitors who land on it. Add &lt;code&gt;app/not-found.js&lt;/code&gt; (App Router) or &lt;code&gt;pages/404.js&lt;/code&gt; (Pages Router) with a clear message, a link back to the homepage, and ideally a search box or links to popular content.&lt;/p&gt;

&lt;p&gt;3 Clean up orphaned routes&lt;/p&gt;

&lt;p&gt;If old static pages or generated paths are no longer linked anywhere on the site but still exist, either remove them or make sure they correctly return a 404/410 status rather than rendering leftover content.&lt;/p&gt;

&lt;p&gt;4 Set up redirects for moved content&lt;/p&gt;

&lt;p&gt;If a page has permanently moved rather than disappeared, use a 301 redirect (via &lt;code&gt;next.config.js&lt;/code&gt; redirects or middleware) instead of letting it soft-404. This preserves any SEO value the old URL had and sends visitors to the right place.&lt;/p&gt;

&lt;p&gt;5 Monitor for new occurrences&lt;/p&gt;

&lt;p&gt;Soft 404s tend to reappear as content changes, new CMS entries get deleted, routes get restructured. Checking Google Search Console's Coverage report periodically (or running a crawler like Screaming Frog) helps catch new ones before they pile up.&lt;/p&gt;

&lt;p&gt;Key Takeaway&lt;/p&gt;

&lt;p&gt;The fix for a soft 404 always comes down to the same principle: if content is genuinely missing, the response needs to say so, not just visually, but in the actual status code the server returns. Next.js gives you the tools (&lt;code&gt;notFound()&lt;/code&gt;, &lt;code&gt;notFound: true&lt;/code&gt;, custom 404 pages, redirects) to do this cleanly; the main job is remembering to use them anywhere content is fetched dynamically.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
