0

想象一下,我有一个在线销售和订单处理应用程序。我有客户、发票、发票项。客户对他们最后一个订单中的某件商品有疑问,并希望将链接发送给他们的销售代表。

Blazor 如何处理这种 URL 应该类似于...的情况

https://myapp.com/customer/12345/Invoice/234/InvoiceItem/4

Blazor 路由引擎可以做到这一点吗?

我已经阅读了多篇博客文章和路由似乎停止: /page/{parameter} 而我真的很喜欢 /page/{parameter}/control/{parameter}/control/{parameter}/etc...

4

1 回答 1

1

这对于 blazor 中的内置功能是绝对可行的,至少在 .NET Core 3.1 和 .NET5 中是这样。使用不同的参数名称很重要,因为它们映射到 razor 组件[Parameter]属性。

对于您的示例,它将是:

@page "/customer/{Customer}/invoice/{Invoice}/invoiceitem/{InvoiceItem}"

<span>Customer: @Customer</span>
<span>Invoice: @Invoice</span>
<span>Item: @InvoiceItem</span>

@code {
    [Parameter] public string Customer {get; set;}
    [Parameter] public string Invoice {get; set;}
    [Parameter] public string InvoiceItem {get; set;}
}
于 2020-11-16T15:25:51.883 回答