粘贴 link 时出现参数空异常

Argument Null Exception when link pasted

我有一个带有主页和嵌套组件的 Blazor Web 程序集应用程序:

@page "/work/{CustomerId:guid}"

@using System.Diagnostics
@using ApplySupportTool.Client.I18nText
@using ApplySupportTool.Client.Services.Contracts
@using ApplySupportTool.Shared.Dto.Customer
@using Toolbelt.Blazor.I18nText

@inject I18nText Localization
@inject ICustomerApi CustomerApi

@attribute [Authorize]


<h3>@string.Format(localizedStrings.WorkOverviewTitle, Customer?.CustomerName)</h3>

<MatTabGroup>
    <MatTab Label="@localizedStrings.TimeTrackingLabel">
        <CascadingValue Value="@CustomerId">
            <TimeTrackingList />
        </CascadingValue>
    </MatTab>

    <MatTab Label="@localizedStrings.WorkItemsLabel">
        Work Items
    </MatTab>
</MatTabGroup>

@code {

    [Parameter]
    public Guid CustomerId { get; set; }

    public CustomerDto Customer { get; set; }
    LocalizedStrings localizedStrings = new LocalizedStrings();

    /// <inheritdoc />
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        localizedStrings = await Localization.GetTextTableAsync<LocalizedStrings>(this);
        Customer = await CustomerApi.GetCustomerByIdAsync(CustomerId);
    }
}

嵌套组件:

@using ApplySupportTool.Client.I18nText
@using ApplySupportTool.Client.Components.Modals
@using ApplySupportTool.Client.Services.Contracts
@using Toolbelt.Blazor.I18nText

@inject I18nText Localization
@inject IModalService Modal
@inject ITimeTrackingApi TimeTrackingApi

@if (false)
{
    <LoadingDialog Title="@localizedStrings.LoadingLabel" IsOpen="true" />
} else
{
    <br />
    <MatButton Label="@localizedStrings.NewTimeTrackingLabel" Raised="true" OnClick="@OpenCreateTimeTrackingDialog" />

    <br />
    <br />

    ... 
    // Mat Blazor Accordion
}

@code {

    [CascadingParameter]
    public Guid CustomerId { get; set; }

    LocalizedStrings localizedStrings = new LocalizedStrings();

    public List<TimeTrackingDto> TimeTrackingDtoList = new List<TimeTrackingDto>();

    /// <inheritdoc />
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        localizedStrings = await Localization.GetTextTableAsync<LocalizedStrings>(this);

        TimeTrackingDtoList = await TimeTrackingApi.GetTimeTrackingAsync(CustomerId);
    }   
}

当我在浏览器中导航时,这按预期工作。但是当我复制 link 它生成并再次粘贴以加载页面时,我得到了很多 wasm 错误:

我检查了我有 string.format 的页面,但没发现有什么问题。所以我假设它可能在解析参数或类似的东西。

知道如何解决这个问题吗?

编辑1: 正如评论中所建议的,我检查了 Guid 是否正确传递。在正常导航中,它无处不在。但是当我粘贴 link 并以这种方式导航时,我只能在主页上看到它,但它似乎没有传递到嵌套组件。 我还尝试用默认字符串参数更改替换 Guid 类型。但这并没有改变任何事情。也没有用普通参数替换级联参数。

在子组件中

[Parameter]
    public Guid CustomerId { get; set; }

应该是

[CascadingParameter]
    public Guid CustomerId { get; set; }

我有以下显示对话框的代码:

<MatDialog @bind-IsOpen="@deleteCustomerDialogOpen" Style="z-index: 100">
    <MatDialogTitle>
        <MatIcon Icon="warning" />@localizedStrings.ConfirmDeleteTitle
    </MatDialogTitle>
    <MatDialogContent>
        @string.Format(localizedStrings.DeleteCustomerConfirmationMessage, SelectedCustomerDto?.CustomerName)
    </MatDialogContent>
    <MatDialogActions>
        <MatButton OnClick="@DeleteCustomerAsync">@localizedStrings.DeleteLabel</MatButton>
        <MatButton OnClick="@(e => { deleteCustomerDialogOpen = false; })">@localizedStrings.CancelLabel</MatButton>
    </MatDialogActions>
</MatDialog>

并且本地化初始化如下: LocalizedStrings localizedStrings = new LocalizedStrings();

/// <inheritdoc />
protected override async Task OnInitializedAsync() {
    localizedStrings = await Localization.GetTextTableAsync<LocalizedStrings>(this);        
}

问题似乎是,在重新加载时 string.format 在正确加载 localizedStrings 之前执行。因此,这导致了问题。我将代码更改为以下修复它的代码:

@string.Format(localizedStrings.DeleteCustomerConfirmationMessage, SelectedCustomerDto?.CustomerName)