In Blazor WASM Preview 1 it was possible to dynamically register a Blazor App via endpoints.MapFallbackToClientSideBlazor<Client.Program>(). This API was removed in Preview 2 and replaced with integration of "ASP.NET Core static web assets".
This change removed the possibility:
To illustrate the scenario I'm trying to achieve:
This was possible in Preview 1:
_applicationBuilder.Map("/ui/App1", app =>
{
app.UseClientSideBlazorFiles<BlazorApp1>();
app.UseEndpoints(endpoints =>
{
endpoints.MapFallbackToClientSideBlazor<BlazorApp1>("index.html");
});
}
_applicationBuilder.Map("/ui/App2", app =>
{
app.UseClientSideBlazorFiles<BlazorApp2>();
app.UseEndpoints(endpoints =>
{
endpoints.MapFallbackToClientSideBlazor<BlazorApp2>("index.html");
});
}
This seems not possible to do in Preview 2.
The above mentioned removed API should be added back or an alternative way should be provided.
Is this related to #19060 ?
@eisendle thanks for contacting us.
This is still possible in preview2. Apps are mapped to '/' by default but you can change StaticWebAssetBasePath on the msbuild project for the app to map it to a different location, like ui/app1 and then you can do as you were doing before:
_applicationBuilder.Map("/ui/App1", app =>
{
app.UseBlazorFrameworkFiles();
app.UseEndpoints(endpoints =>
{
endpoints.MapFallbackToFile("index.html");
});
}
The above mentioned code snippet doesn't work. After a lot of tinkering this works partially for me:
_applicationBuilder.UseStaticFiles();
_applicationBuilder.UseBlazorFrameworkFiles("/ui/App1");
However the fallback for "/ui/App1" to index.html isn't working.
Using the default Blazor WASM template I've tried multiple things:
_applicationBuilder.Map("/blazor/app", x =>
{
x.UseRouting();
x.UseEndpoints(endpoints =>
{
endpoints.MapFallbackToFile("index.html");
});
});
```csharp
_applicationBuilder.Map("/blazor/app", x =>
{
x.UseRouting();
x.UseEndpoints(endpoints =>
{
endpoints.MapFallbackToFile("/blazor/app/index.html");
});
});
```csharp
_applicationBuilder.UseEndpoints(endpoints =>
{
endpoints.MapFallbackToFile("/blazor/app/index.html");
});
None of the above mentioned attempts does the trick, maybe I'm missing something
From a documentation point of view, there should be an example in the docs which shows how to host a Blazor WASM app on a non root location.
yes, it's a way too complex to guess the appropriate configuration without any docs or example ...
here it is my working solution: https://github.com/luposky/TestBlazorPath
it's the basic example from wasm template with these modifications:
https://github.com/luposky/TestBlazorPath/commit/6e01f2dbea3955789f24c44fb55e9c78783e6b87
please review and share if it working in your scenario (you need to add "/portal" manually on the address bar) ...
@luposky
Thanks, it's now working for my scenario too. Problem was the leading slash in variant two in my above comment.
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.
Most helpful comment
yes, it's a way too complex to guess the appropriate configuration without any docs or example ...
here it is my working solution: https://github.com/luposky/TestBlazorPath
it's the basic example from wasm template with these modifications:
https://github.com/luposky/TestBlazorPath/commit/6e01f2dbea3955789f24c44fb55e9c78783e6b87
please review and share if it working in your scenario (you need to add "/portal" manually on the address bar) ...