Microsoft.AspNetCore.Components.WebAssembly.Server nuget package to the existing project<StaticWebAssetBaseBath>clientapp</StaticWebAssetBaseBath> to Blazor csproj<base href="/clientapp" /> and prefix all the paths of link href with "clientapp" as the URL segment for WASMapp.MapWhen(ctx => ctx.Request.Path.StartsWithSegments("/clientapp"), app1 =>
{
   app1.UseBlazorFrameworkFiles("/clientapp");
   app1.UseRouting();
   app1.UseEndpoints(endpoints =>
   {
       //endpoints.MapControllers();
       endpoints.MapFallbackToFile("/clientapp/{*path:nonfile}", "/clientapp/index.html");
   });
   //app1.UsePathBase("/clientapp");
   app1.UseStaticFiles();
   app1.UseStaticFiles("/clientapp");
});
app.UseWebAssemblyDebugging(); to the existing project > Program.csSource code on GitHub
Getting HTTP 404 not found error on doing the above steps, running the project and navigating to /clientapp.
Setting up the two projects is relatively simple. You're almost there. Sorting out the navigation can be a bit problematic!
Adding a WASM project is very simple.
    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.4" />
    </ItemGroup>
Program.app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
Copy index.html from the WASM project to the web project Shared folder and rename to Wasm.cshtml.
Add the following to the top of the page.
@page "/wasm"
@{
    Layout = null;
}
            <li class="nav-item">
                <a class="nav-link text-dark" href="/Wasm">Blazor</a>
            </li>
@page "/Wasm"
<PageTitle>Index</PageTitle>
NavMenu in the WASM project.        <div class="nav-item px-3">
            <NavLink class="nav-link" href="/">
                <span class="oi oi-plus" aria-hidden="true"></span>Server
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="/wasm">
                <span class="oi oi-home" aria-hidden="true"></span> Home
            </NavLink>
        </div>
You should now be able to navigate between the projects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With