0

I'm currently unable to make React Routing working in azurewebsites.net. Everything works smoothly in localhost, but when I deploy the application to Azure Routing stops working.

Application shows default frontpage ex. "example.azurewebsites.net" but if I try to open "example.azurewebsites.net/about" I get "Cannot GET (urlparam)" error.

I tried to add the following file called web.config under public folder, but it doesn't seem to help.

<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
  <rules>
    <rule name="React Routes" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>
  </rules>
</rewrite>
</system.webServer>
</configuration>

Does anyone have an idea how to fix this? Please ask if something from the code is needed, I'm not sure what else I should provide here.

aksoco
  • 131
  • 1
  • 13
  • 1
    Maybe the underlying paths are blocked, try to switch to the hashrouter `import { HashRouter } from 'react-router-dom'` – henk Apr 06 '22 at 10:43

1 Answers1

0

Maybe your xml file shouldn't be formated. I'm not sure but I saw on some blog post that it is very sensitive and shouldn't be formated.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 20 '22 at 18:08