DEV Community

Cover image for 🚀 How I Fixed Canonical & Indexing Issues on My React SPA (Cloudflare Pages + Custom Domain)
Sujit Chanda
Sujit Chanda

Posted on

🚀 How I Fixed Canonical & Indexing Issues on My React SPA (Cloudflare Pages + Custom Domain)

I recently launched a small browser-based utility platform built with React and hosted on Cloudflare Pages.

Everything looked fine.

  • Sitemap submitted
  • Robots.txt configured
  • Google Search Console verified
  • Pages discovered

But after 2 weeks…
Only 1 page was indexed.

The rest showed:

  • “Duplicate, Google chose different canonical than user”
  • “Discovered – currently not indexed”

Here’s what was actually wrong.

The Problem

I had both domains active:

Both were:

  • Live
  • SSL enabled
  • Returning 200 status
  • Serving identical content

I assumed Cloudflare Pages would automatically handle canonical preference.

It didn’t.

Google saw two hosts serving identical pages and started choosing its own canonical.

For a new domain with zero authority, that slows everything down.

What Was Happening Internally

Search Console showed:

  • User-declared canonical → non-www
  • Google-selected canonical → www

This split signals and delayed indexing.
For a brand new SPA, that’s deadly.

The Fix

- Force a Single Host (301 Redirect)

In Cloudflare → Rules → Redirect Rules:
Condition:
Hostname equals www.optipress.in

Action:
Redirect to https://optipress.in${uri}
Status: 301

After deploying, www permanently redirects to non-www.

Add Canonical Tag

Inside <head>: <link rel="canonical" href="https://optipress.in/" />

And for every route:
<link rel="canonical" href="https://optipress.in/specific-page" />

Purge Cloudflare Cache

After redirect change, purge everything.

Re-Request Indexing

In Search Console:
Inspect URL
Request indexing again

SPA-Specific Observation

My site is a pure React SPA:
<div id="root"></div>

That means:

  • Minimal initial HTML
  • Content rendered via JS
  • Slower indexing for new domains

Lesson learned:
If you’re launching a JS-heavy site, domain consolidation matters even more.

What I Learned

Always choose one primary host early
Don’t assume hosting platforms auto-handle canonical logic
New domains + SPAs = slower indexing
Fix technical structure before chasing backlinks

Check out : https://optipress.in

Top comments (0)