When I try to do a GET call to a subroute of my react application I get a 404. When I do this to my homepage it returns correctly the HTML. When just accessing the subroutes via the browser my webpage gets correctly rendered. I'm Using React version 16.9.0. I'm hosting the web application in Azure App service.
The reason for this question is to use an external program that can check for deadlinks in a website. At the moment I get 404's for every call to a subroute.
GET calls in Postman:
www.test.be => works
www.test.be/custom-route => gives a 404
This is my React Router Wrapper component:
import React from 'react';
import { Switch, Route } from 'react-router-dom';
import Home from 'home/containers/home-container.js';
import NotFoundPage from './error-pages/not-found-page';
import Questions from 'questions/containers/question-container.js';
const Body = () => {
return (
<Switch>
<Route path="/" exact component={Home} />
<Route path="/questions" component={Questions} />
<Route component={NotFoundPage} />
</Switch>
);
};
export default Body;
This is my web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime requestPathInvalidCharacters="<,>,*,&,:,\\,?" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<rule name="HTTPSs">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="Off"/>
<add input="{HTTP_HOST}" negate="true" pattern="^localhost" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
<rule name="ReactRoutes" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_METHOD}" pattern="^GET$" />
<add input="{HTTP_ACCEPT}" pattern="^text/html" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering allowDoubleEscaping="true"/>
</security>
</system.webServer>
</configuration>