← Back to React Course | Chapter 14: Performance & Production Deployment | Lesson 13 of 13

React SPAs के लिए SEO Basics

एक React app के लिए SEO यह confirm करने जैसा है कि आपकी store के बाहर clear signs हैं ताकि search engines (और customers) असल में ढूंढ और समझ सकें कि अंदर क्या है, दूर से भी।

Client-Side Rendering SEO को क्यों नुकसान पहुंचा सकता है

एक plain client-side React app की initial HTML अक्सर सिर्फ एक empty <div id=root></div> होती है — असली content JavaScript चलने के बाद ही दिखता है। जबकि major search engines JavaScript execute करने में बेहतर हुए हैं, यह extra step अब भी indexing की speed और completeness को असर डाल सकता है उस content के comparison में जो initial HTML में पहले से मौजूद हो।

Note: content-heavy, SEO-critical pages के लिए (जैसे एक blog या marketing site), server-side rendering या static generation (Next.js जैसे एक framework के through) ज़्यादा reliable choice है।
Warning: हर crawler (search engines, social media link previews, कुछ bots) JavaScript equally well execute नहीं करता — pure client-side rendering SEO-sensitive pages के लिए एक असली risk है।

Page Titles और Meta Tags Manage करना

एक single-page app में हर distinct page का अपना unique, descriptive <title> और meta description होना चाहिए — दोनों important signals इसके लिए कि search engines और shared links उस specific page को कैसे represent करती हैं।

react-helmet-async जैसी एक library आपको इन्हें per route dynamically set करने देती है।

Note: वे titles और descriptions लिखें जो उस SPECIFIC page के content को describe करें, एक generic title नहीं जो हर route पर reuse हो।
Warning: हर page को वही default <title> (सिर्फ app के नाम जैसा) छोड़ना search engines और users के लिए अलग-अलग pages को search results में distinguish करना कहीं ज़्यादा मुश्किल बना देता है।

उदाहरण: Managing Page Titles and Meta Tags

markup
// Run in your local React project (npm install required)
import { Helmet } from 'react-helmet-async';

function ProductPage({ product }) {
  return (
    <div>
      <Helmet>
        <title>{product.name} - My Store</title>
        <meta name="description" content={product.summary} />
      </Helmet>
      <h1>{product.name}</h1>
    </div>
  );
}

⚠️ This example uses an npm package with no CDN build available here — run this in your local React project.

Semantic HTML SEO में भी मदद करता है

वही semantic HTML practices जो accessibility में मदद करती हैं — main heading के लिए एक असली <h1>, navigation के लिए <nav>, primary content के लिए <main> उपयोग करना — search engines को भी एक page की structure और importance hierarchy समझने में मदद करती हैं, क्योंकि crawlers content interpret करने के लिए यही same signals उपयोग करते हैं।

Note: एक page में generally exactly एक <h1> होना चाहिए, उस page के main topic को clearly describe करते हुए, logical subsections के लिए <h2>/<h3> उपयोग करते हुए।
Warning: हर चीज़ के लिए generic <div> elements उपयोग करना (semantic tags के बजाय) search engines को आपके page की असल structure और importance के बारे में कहीं weaker signals देता है।

उदाहरण: Semantic HTML Helps SEO Too

markup
<!DOCTYPE html>
<html>
<head>
  <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
  <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
  <div id="root"></div>
  <script type="text/babel">
function ArticlePage() {
  return (
    <main>
      <h1>How React Works</h1>
      <nav aria-label="Table of contents"><a href="#intro">Introduction</a></nav>
      <h2 id="intro">Introduction</h2>
      <p>React is a JavaScript library for building UIs.</p>
    </main>
  );
}
ReactDOM.createRoot(document.getElementById('root')).render(<ArticlePage />);
  </script>
</body>
</html>
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. उस content के लिए पूरी तरह client-side rendering पर रहना जिसे index होना ज़रूरी है, क्योंकि कुछ crawlers JavaScript पूरी तरह execute नहीं कर सकते।
  2. एक multi-page app में हर page के लिए एक unique, descriptive <title> और meta description set करना भूल जाना।
  3. meaningful alt text और semantic HTML न देना, जो यह भी असर डालता है कि search engines page content को कैसे समझते हैं।
चैप्टर सारांश
  • एक pure client-side-rendered React app search engines के लिए एक server-rendered page से ज़्यादा index करना मुश्किल हो सकता है।
  • Server-side rendering या static generation (जैसे Next.js के through) असली HTML content produce करता है जिसे crawlers तुरंत पढ़ सकते हैं।
  • हर page को एक unique, descriptive <title> और meta description चाहिए, एक single-page app में dynamically managed।
  • Semantic HTML और proper heading structure (h1, h2...) accessibility और SEO दोनों को simultaneously मदद करते हैं।
ब्राउज़र सपोर्ट

कोई React-version restriction नहीं — SEO rendering strategy और semantic markup पर depend करता है, किसी specific React API पर नहीं।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.