In my test, the blazorwebview's default url is https://0.0.0.0/, so you can call the platform code to reload the url. But to make the url always correct, I get it programmatically.
In the MainPage:
public partial class MainPage : ContentPage { public string url; public BlazorWebView view; public MainPage() { InitializeComponent(); view = blazorWebView; } public void Reload() {#if Android var androidweb = blazorWebView.Handler.PlatformView as Android.Webkit.WebView; androidweb.LoadUrl(url);#elif WINDOWS var windowweb = blazorWebView.Handler.PlatformView as Microsoft.UI.Xaml.Controls.WebView2; windowweb.Source = new Uri(url);#elif IOS var iosweb = blazorWebView.Handler.PlatformView as WebKit.WKWebView; iosweb.LoadRequest(new Foundation.NSUrlRequest(new Uri(url)));#endif } }
In the Home.Razor:
@code{ protected override void OnInitialized() { base.OnInitialized();#if Android var androidweb = (App.Current.MainPage as MainPage).view.Handler.PlatformView as Android.Webkit.WebView; (App.Current.MainPage as MainPage).url = androidweb.Url;#elif WINDOWS var windowweb = (App.Current.MainPage as MainPage).view.Handler.PlatformView as Microsoft.UI.Xaml.Controls.WebView2; (App.Current.MainPage as MainPage).url = windowweb.Source.ToString();#elif IOS var iosweb = (App.Current.MainPage as MainPage).view.Handler.PlatformView as WebKit.WKWebView; (App.Current.MainPage as MainPage).url = iosweb.Url.ToString();#endif }}
And then you can call the Reload method to reload the blazor webview. Why I get the default Url in the Home.Razor is I can't get it in the MainPage's life cycle method on the windows platform.