1

MatBlazor 文档说“要为所有应用程序应用主题,您可以在 MainLayout.razor 或 App.razor 中使用 MatThemeProvider”

这个例子的信息很薄。

将代码片段添加到 MainLayout.razor 或 App.razor 时,它只是不起作用。

我得到的错误是“InvalidOperationException:路由器组件需要找到参数的值。”

您如何为整个应用程序应用主题?

App.razor

<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">

        <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
            <Authorizing>
                <p>Determining session state, please wait...</p>
            </Authorizing>
            <NotAuthorized>
                <Unauthorised />
            </NotAuthorized>
        </AuthorizeRouteView>

        <MatThemeProvider Theme="@theme">
            <Router AppAssembly=typeof(Pages.Dashboard).Assembly />
        </MatThemeProvider>

    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(MainLayout)">
            <p>Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</Router>

@code
    {
    MatTheme theme = new MatTheme()
    {
        Primary = MatThemeColors.Orange._500.Value,
        Secondary = MatThemeColors.BlueGrey._500.Value
    };
}
4

1 回答 1

3

你能试试这个吗?

<MatThemeProvider Theme="@theme">
<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">

        <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
            <Authorizing>
                <p>Determining session state, please wait...</p>
            </Authorizing>
            <NotAuthorized>
                <Unauthorised />
            </NotAuthorized>
        </AuthorizeRouteView>
    </Found>  
    <NotFound>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </NotFound>
    </Router>
</MatThemeProvider>

@code
    { MatTheme theme = new MatTheme()
        {
         Primary = MatThemeColors.Orange._500.Value,
         Secondary = MatThemeColors.BlueGrey._500.Value
        }; 
    }

请让我知道它是否有效。:)

于 2020-06-25T23:33:03.107 回答