dotnet / dotnet/aspnetcore

Blazor Routing on sub pages not working when using different path base

Open
#54,469 0 comments 0 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

We have a Blazor .NET 8 WebApp with a blue/green deployment. Incoming requests have a path like `/blue/page` or `/green/page`. To react to blue and green requests we used this in .NET 7:

```
app.UseWhen(ctx => ctx.Request.Path.StartsWithSegments("/blue"), app =>
{
app.UsePathBase("/blue");
});

app.UseWhen(ctx => ctx.Request.Path.StartsWithSegments("/green"), app =>
{
app.UsePathBase("/green");
});
```

After migrating to .NET 8 we have a problem with this approach because requests to sub pages don't work anymore. If the request is `/blue/sub/page` Blazor is looking for `/blue/sub/_framework/blazor.web.js`. If `` is included in the `App.razor` the sub pages work but only at the root request path (`/green` and `/blue` cannot be used).

Reproducible example is located [here](https://github.com/audacity76/BlazorWebApp8).

This is also related to https://github.com/dotnet/aspnetcore/issues/51929

### Expected Behavior

_No response_

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

8.0.200

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.