Last active
December 16, 2020 09:34
-
-
Save danielplawgo/9875ecd54e76d7ae0b7ee59bdb457159 to your computer and use it in GitHub Desktop.
Blazor Lazy Loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using System.Reflection | |
<Router AppAssembly="@typeof(Program).Assembly" | |
AdditionalAssemblies="@assemblies"> | |
<Found Context="routeData"> | |
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | |
</Found> | |
<NotFound> | |
<LayoutView Layout="@typeof(MainLayout)"> | |
<p>Sorry, there's nothing at this address.</p> | |
</LayoutView> | |
</NotFound> | |
</Router> | |
@code { | |
private List<Assembly> assemblies = new List<Assembly>() | |
{ | |
typeof(Users.UsersModule).Assembly | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using System.Reflection | |
@using Microsoft.AspNetCore.Components.Routing | |
@using Microsoft.AspNetCore.Components.WebAssembly.Services | |
@inject LazyAssemblyLoader assemblyLoader | |
<Router AppAssembly="@typeof(Program).Assembly" | |
AdditionalAssemblies="@assemblies" | |
OnNavigateAsync="@OnNavigateAsync"> | |
<Navigating> | |
<div style="padding:20px;background-color:blue;color:white"> | |
<p>Loading the requested page…</p> | |
</div> | |
</Navigating> | |
<Found Context="routeData"> | |
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | |
</Found> | |
<NotFound> | |
<LayoutView Layout="@typeof(MainLayout)"> | |
<p>Sorry, there's nothing at this address.</p> | |
</LayoutView> | |
</NotFound> | |
</Router> | |
@code { | |
private List<Assembly> assemblies = new List<Assembly>(); | |
private async Task OnNavigateAsync(NavigationContext args) | |
{ | |
try | |
{ | |
if (args.Path.StartsWith("users")) | |
{ | |
var loadedAssemblies = await assemblyLoader.LoadAssembliesAsync( | |
new List<string>() { "BlazorLazyLoading.Client.Users.dll" }); | |
assemblies.AddRange(loadedAssemblies); | |
} | |
} | |
catch (Exception ex) | |
{ | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ItemGroup> | |
<BlazorWebAssemblyLazyLoad Include="BlazorLazyLoading.Client.Users.dll" /> | |
</ItemGroup> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page "/users" | |
<h3>Users</h3> | |
<p>This component display the users list.</p> | |
@code { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UsersModule | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment