Publishing a React App with Routing to a Linux Azure Web App

19 February, 2024

ReactAzureDevOps

The trick to this is knowing that under the hood, Azure web apps that are running on Linux use the PM2 process manager to keep the web app online.

Once this is understood, the solution becomes relatively simple as the PM2 documentation itself makes mention of how to handle SPA applications. This will then make sure that all URL requests are redirected to the index.htrml file, which in our case is the React index.

For our Azure web app, all we need to do is update the start-up command to let PM2 know we are running a SPA application:

// Start up command needs to be: pm2 serve /home/site/wwwroot/build --no-daemon --spa

To do this for your Azure web app, open the app in the portal, navigate to configuration, then general settings then Startup Command.

Azure-portal-app-config-settings

After saving this setting, restart the web app and you will be able to navigate tothe routes configured in your React App.

If you liked this post, please share it!