我正在进行一个blazor服务器端项目,该项目使用了两种不同的布局。项目的组织方式如下
_Layout
<!DOCTYPE html>
<html lang="en">
<head>
ref to all css files
</head>
<body>
@RenderBody()
<scripts>
ref to all js files
</scripts>
</body>
然后
_MainLayOut
@Body
然后
_EmptyLayout
<style type="text/css">
define my custom styles for this layout But I dont want to load any of the css & js files with this layout
</style>
@Body
应用程序使用MainLayout作为App.razor下的默认布局
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
自定义EmptyLayoutPage的示例如下
@page "/customlayout_simple"
@layout EmptyLayout
@inject NavigationManager navManager
<div>My page contents</div>
当EmptyLayoutPage在检查时加载时,我可以看到所有与_Layout相关联的css和脚本都在加载
与我的EmptyLayout样式冲突
我试图将脚本从_Layout放置到MainLayout,但出现了错误
脚本标记不应放置在组件内部,因为它们不能动态更新。若要解决此问题,请将脚本标记移动到“”索引中。html'文件或其他静态位置
那么,我如何确保在加载EmptyLaout页面时,与_Layout关联的css和js不会加载
或者,我如何指定位于Layout内部的js和css,仅用于MainLayout