dotnet / dotnet/aspnetcore

Using MapGroup with Blazor endpoints produces template error

Open
#64,965 0 comments 1 reaction 0 assignees View on GitHub
area-blazor investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Similar to https://github.com/dotnet/aspnetcore/issues/57843, but when I use MapGroup to map blazor endpoints to a different base path, I get the error:

`InvalidOperationException: Unable to find the provided template '/blazor/'`

In the blazor template, I replace

```
app.MapStaticAssets();
app.MapRazorComponents()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(BlazorBasePath.Client._Imports).Assembly);
```

with

```
var groupBuilder = app.MapGroup("/blazor");

groupBuilder
.MapStaticAssets();

groupBuilder
.MapRazorComponents()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(BlazorBasePath.Client._Imports).Assembly);
```

I suppose the first question is, is that a valid thing to do? The issue I mentioned above does it using UsePathBase, but it seemed better to do what I want with the newer MapGroup feature.

### Expected Behavior

Blazor site loads in new base path

### Steps To Reproduce

Repo: https://github.com/ptsoccer/BlazorBasePath

1. Create new Blazor Web App with WebAssembly as the interactive render mode. Other render modes might also error out, but I need WebAssembly.
2. Replace
```
app.MapStaticAssets();
app.MapRazorComponents()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(BlazorBasePath.Client._Imports).Assembly);
```
with

```
var groupBuilder = app.MapGroup("/blazor");

groupBuilder
.MapStaticAssets();

groupBuilder
.MapRazorComponents()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(BlazorBasePath.Client._Imports).Assembly);
```

in the generated template

3. Run the website and browse to /blazor, you should get the error mentioned above.

### Exceptions (if any)

_No response_

### .NET Version

10.0.101

### Anything else?

Microsoft.NETCore.App 10.0.1
Microsoft.AspNetCore.App 10.0.1

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.