01 Deploy to github pages – that are not root enabled
To display to Githbub pages ( i.e. https://ignatandrei.github.io/BlazorBrowserHistory/ ) the base href must be overwritten
To do so I have been doing in index.html with a powershell script found in src\BBH\modifyPostData.ps1
Write-Host "modify index.html"
$indexFilePath = "Release/UIBlazor/wwwroot/index.html"
$Content = Get-Content -Path $indexFilePath -Raw
$updatedContent = $Content -replace '"./_framework/', '"/BlazorBrowserHistory/_framework/'
$updatedContent = $Content -replace '<base href="/" />', '<base href="/BlazorBrowserHistory/" />'
Set-Content -Path $indexFilePath -Value $updatedContent
#TODO: delete br and gz files
Remove-Item -Path "Release/UIBlazor/wwwroot/index.html.br"
Remove-Item -Path "Release/UIBlazor/wwwroot/index.html.gz"
# handle 404.html
Copy-Item -Path $indexFilePath -Destination "Release/UIBlazor/wwwroot/404.html"
Write-Host "modify app base back"
$settingsFilePath = "BBH/wwwroot/appsettings.json"
$settingsContent = Get-Content -Path $settingsFilePath -Raw
$updatedSettingsContent = $settingsContent -replace '"AppBasePath": "/BlazorBrowserHistory/"','"AppBasePath": "/"'
Set-Content -Path $settingsFilePath -Value $updatedSettingsContent
Write-Host "Change back AppBasePath in $settingsFilePath "
Write-Host "Change back AppBasePath in $indexFilePath "
and, because I need also in app.razor for a sqlite component , in src\BBH\modifyBlazor.ps1
Write-Host "modify app base"
$settingsFilePath = "BBH/wwwroot/appsettings.json"
$settingsContent = Get-Content -Path $settingsFilePath -Raw
$updatedSettingsContent = $settingsContent -replace '"AppBasePath": "/"', '"AppBasePath": "/BlazorBrowserHistory/"'
Set-Content -Path $settingsFilePath -Value $updatedSettingsContent
Write-Host "Change back AppBasePath in $settingsFilePath "
The appsettings.json is the following
{
"AppBasePath": "/",
"DatabaseProvider_Fake": "SqliteWasmBlazor",
"DatabaseProvider" :"BitBesql"
}
02 Switch between the 2 implementations
To switch between the 2 implementations of Sqlite in WASM I imagined putting in appsettings.json
{
"AppBasePath": "/",
"DatabaseProvider_Fake": "SqliteWasmBlazor",
"DatabaseProvider" :"BitBesql"
}
And modifying manually every time . However, on long term, this is not feasible. So I used https://www.nuget.org/packages/BlazorExtensionsAspire/ and the code allows me to switch between the 2 providers in Aspire
var bbh= builder.AddProject<BBH>("BlazorBrowserHistory")
.AddCommandsToModifyEnvName(new BBH(), "SqliteWasmBlazor", "BitBesql");
This is the picture 
What it does is to read from 2 different appsettings based on environment in index.html
<script src="_framework/blazor.webassembly#[.{fingerprint}].js" autostart="false"></script>
<script>
Blazor.start({
environment: "SqliteWasmBlazor"
});
</script>
And in C# i read the configuration
var builder = WebAssemblyHostBuilder.CreateDefault(args);
await LoadConfigurationAsync(builder);
var dbProviderStr = builder.Configuration["DatabaseProvider"];
public static async Task LoadConfigurationAsync(WebAssemblyHostBuilder builder)
{
var BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
var dict = await FromSettings(BaseAddress,"");
var env = builder.HostEnvironment.Environment;
var res = await FromSettings(BaseAddress, env);
foreach(var kvp in res)
{
dict[kvp.Key]= kvp.Value;
}
builder.Configuration.AddInMemoryCollection(dict.ToArray());
}
03 WASM Tools
It worked on my pc, BUT on deploy not. Why ?
- name: Install wasm-tools workload
run: dotnet workload install wasm-tools
Demo at https://ignatandrei.github.io/BlazorBrowserHistory/
Nuget Packages at https://www.nuget.org/packages?q=BBH+owner%3Aignatandrei&includeComputedFrameworks=true&prerel=false&sortby=relevance