Marvin
Marvin

Reputation: 443

React Router - Ignore / Redirect to subfolder

Is it possible to ignore a specific URL in the react router?

I have an app for a service desk app in a subdir which I can not reach, once I have entered the react app.

<Route
  exact
  path="/"
  component={ViewHome}
/>

<Route
  path="/about"
  component={ViewAbout}
/>

<Route
  path="/help"
  // Ignore the React App and forward this request to the server.
/>

As Marvin stated in his answer, this could be a server config problem. Here is the content of the .htaccess rewrite.

RewriteEngine On
RewriteBase /

RewriteRule ^(help)($|/) - [L]

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

Any ideas?

Upvotes: 1

Views: 1959

Answers (1)

MarvinVK
MarvinVK

Reputation: 3083

I don't know if I understand your question, but this sounds like a server configuration issue.

For example, I use Nginx on my server to configure the router. The usual behavior of your browser is to search for a subdirectory when you do /something.

But if you configure it in a way that your servers keeps looking at your index file it should be fine.

What works for me in my Nginx config:

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

Upvotes: 2

Related Questions