Rayberk
Rayberk

Reputation: 133

React Build Pages/Router/SEO/Sitemap

I have an react web app and it has routes like about,contact etc... When i type "x.x/route" to the browser i get "404 Not Found" but when i click to the link with the component i get the page and my url = "x.x/route" even i get 404 in manual type

And in sitemap.xml i do not receive the routes

So ... is there anyway to make it optimized for SEO or SITEMAP.XML ? or how can i make a build with folders

Upvotes: 1

Views: 355

Answers (1)

Tsetsi
Tsetsi

Reputation: 46

the problem you are presenting is caused because the engine you are using isn't configured properly. I will post Apache and Nginx ones but there are also methods for Express and some others.

For apache this can help:

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html [L]

</IfModule>

For Ngnix add to the site file:

location / {
  try_files $uri /index.html;
}

Have a nice day.

Upvotes: 2

Related Questions