Azure / Azure/static-web-apps

Unable to configure a navigation fallback per route with staticwebapp.config.json

Open
#1,124 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
346
Forks
67
PR merge metrics
No merged PRs in 30d

Description

I use the same Azure Static WebApp to host multiple docs.
Each doc is an Angular application maintained by a team.

I have a pipeline that deploys every doc dist in the `docs` directory of the Azure Static WebApp :

```
/docs/angular-app-1
/docs/angular-app-2
```

My Azure pipeline looks like this :

```yaml
- task: AzureStaticWebApp@0
inputs:
is_static_export: true
app_location:docs
skip_app_build: true
skip_api_build: true
azure_static_web_apps_api_token: SOME_TOKEN
```

The `baseHref` of each Angular application varies:

angular-app-1: `baseHref="/angular-app-1/"`
angular-app-2: `baseHref="/angular-app-2/"`

To prevent 404 error when refreshing a page, a navigation fallback to `index.html` of each Angular app is required.
To achieve this, I added a `routes.json` file into `docs` directory:

```json
{
"routes": [
{
"route": "/angular-app-1/*",
"serve": "angular-app-1/index.html",
"statusCode": 200
}
{
"route": "/angular-app-2/*",
"serve": "angular-app-2/index.html",
"statusCode": 200
},
]
}
```

It works as expected but `routes.json` is deprecated since months in favor of `staticwebapp.config.json`.

Is there a way to configure a navigation fallback per Angular application with the new configuration file ?

```json
{
"navigationFallback": {
"rewrite": "index.html"
}
}
```

In my case `navigationFallback.rewrite` should be :
- `angular-app-1/index.html` for `angular-app-1`
- `angular-app-2/index.html` for `angular-app-2`

I have tried putting a `staticwebapp.config.json` file with the appropriate navigation fallback in each Angular application distribution, but without success.

I can't figure out how to convert `routes.json` configuration to `staticwebapp.config.json`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.