MatBlazor 按钮 Link 未被路由解析

MatBlazor Button Link is not parsed by routing

我正在为我的网站使用 MatBlazor,并且我已经使用这个很棒的博客实现了 Google 身份验证: Google Authentication in Server-Side Blazor

我想要 MatAppBar 中的登录按钮 (MatButton)。

原代码有一个link:<a class="ml-md-auto btn btn-primary" href="/Login" target="_top">Login</a>.
这 link 有效。我被重定向到 LoginModelOnGetAsync。但它不符合我的 UI 风格。

这个按钮确实转到了正确的页面,但是我的 LoginModelOnGetAsync 没有被触发,只显示默认的 Sorry, there's nothing at this address.
<MatButton Class="mat" Outlined="true" Icon="Google" Label="Inloggen" Link="/Login"></MatButton>

我想我需要调整路由,但找不到具体方法。

更新:
我的 Login.cshtml.cs:

[AllowAnonymous]
public class LoginModel : PageModel
{
    public IActionResult OnGetAsync(string returnUrl = null)
    {
        string provider = "Google";
        // Request a redirect to the external login provider.
        var authenticationProperties = new AuthenticationProperties
        {
            RedirectUri = Url.Page("./Login",
            pageHandler: "Callback",
            values: new { returnUrl }),
        };
        return new ChallengeResult(provider, authenticationProperties);
    }
}

我的Startup.cs:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseCookiePolicy();
        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEmbeddedBlazorContent(typeof(MatBlazor.BaseMatComponent).Assembly);

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapBlazorHub();
            endpoints.MapFallbackToPage("/_Host");
        });
    }

使用完整的 URL

<MatButton Class="mat" Outlined="true" Icon="Google" Label="Inloggen"
 Link="BaseUrl/Login"></MatButton>

或 使用导航管理器导航该页面

@inject NavigationManager navigationmanager
    <MatButton Class="mat" Outlined="true" Icon="Google" Label="Inloggen" Onclick="@(()=>)"></MatButton>
    code{
void clic()
{
navigationmanager.Navigateto("/Login")
}
}

我有一个非常相似的问题并使用了上面列出的 navigationmanager 选项,但必须将 ForceLoad 参数作为 "true"

 void LoginClick()
            {
                navigationManager.NavigateTo("/login",true);
            }