【问题标题】:Adding MatBlazor MatThemeProvider in MainLayout.razor or App.razor在 MainLayout.razor 或 App.razor 中添加 MatBlazor MatThemeProvider
【发布时间】:2020-05-18 09:20:56
【问题描述】:

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

这个例子的信息很薄。

将代码 sn-p 添加到 MainLayout.razor 或 App.razor 时它不起作用。

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

如何为整个应用应用主题?

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
    };
}

【问题讨论】:

  • The Router component 你确定这是关于 matblazor 的吗?请说明您添加MatThemeProvider 的方式和位置,但似乎还有另一个问题
  • 查看更新的代码。如果我删除 那么一切正常。
  • 将其放入MainLayout 并将其从您在问题中更新的代码中删除时会怎样?
  • 同样的事情 - 不知道我怎么弄错了!

标签: blazor matblazor


【解决方案1】:

你可以试试这个吗?

<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
        }; 
    }

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

【讨论】:

    猜你喜欢
    • 2021-04-15
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 2020-04-16
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多