Hash-URL’s zijn een SIGNIFICANT probleem:
Hoe crawlers hash-URL’s zien:
- Jouw URL:
example.com/#/products/shoes - Wat crawler ziet:
example.com/ - Alle hash-routes = dezelfde pagina voor crawlers
De oplossing - gebruik History API:
// Voorheen (hash-routing)
<Route path="/#/products/:id" />
// Daarna (browser history)
<Route path="/products/:id" />
// Configureer React Router
<BrowserRouter>
<Routes>
<Route path="/products/:id" element={<Product />} />
</Routes>
</BrowserRouter>
Serverconfiguratie nodig:
# nginx - serveer index.html voor alle routes
location / {
try_files $uri $uri/ /index.html;
}
Prioriteit: Dit is eigenlijk belangrijker dan prerendering. Hash-URL’s betekenen dat crawlers je pagina’s letterlijk niet kunnen onderscheiden.
Fix eerst de URL’s, implementeer daarna prerendering.