Blazor: Get Current Page at MainLayout

Blazor, 經由 @Body 取得 Current Page。Get current page at main-layout. 實作麵包屑breadcrumbs。

目的

在 main layout 取得現在的 Razor page 的屬性,用於顯示現在執行狀態或實作「麵包屑 bread-crumbs」。

程式碼紀錄

一 、自訂 Page Attributes。

PageAttribute.cs
using System;

namespace BlazorServerApp
{
    public class PageAttribute : Attribute
    {
        public PageAttribute(string id, string name)
        {
            FuncId = id;
            FuncName = name;
        }

        public string FuncId { get; }
        public string FuncName { get; }
    }
}

二、在 @page 加入自訂 Page Attributes。

三、在MainLaout.razor 元件取得 Current Page

Last updated