.NET 9 - Static SSR pages in a globally-interactive app

1.简单介绍

.NET 9 Blazor 新增加的一个feature是在Interactive模式的Blazor站点中可以设定某个页面为Static SSR模式。

这边也简单尝试一下这个新的特性

2.具体说明

2.1 创建项目

  1. 创建一个Blazor Web Assembly的项目,

2)编辑App.razor

复制代码
<head>
	...
    <HeadOutlet @rendermode="@PageRenderMode" />
</head>
<body>
    <Routes @rendermode="@PageRenderMode" />
    ...
</body>
@code {
    [CascadingParameter]
    private HttpContext HttpContext { get; set; } = default!;

    private IComponentRenderMode? PageRenderMode
        => HttpContext.AcceptsInteractiveRouting() ? InteractiveWebAssembly : null;
}

3)把Weather.razor页面变成Static SSR,

复制代码
@page "/weather"
@attribute [ExcludeFromInteractiveRouting]

2.2 运行一下

发现Weather.razor页面能正常工作,同时页面是服务器端渲染之后传到浏览器的

这时如果是从Counter页面跳转到Weather页面,发现服务端会重新渲染并下载的Weather页面

如果Weather.razor页面没有设定 @attribute [ExcludeFromInteractiveRouting]

则Weather页面也是InterActiveWebAssemblyRenderMode的,和别的页面一样的render mode。测试了一下,发现这种情况下从Counter页面跳转到Weather页面是没有从服务器端重新下载Weather页面的。

3.总结

本文简单尝试了一下在全局设定为Interactive(可以为InteractiveServer,InteractiveWebAssembly,

InteractiveAuto)情况下,如何将其中一个页面变成Static SSR,同时看看和未变成Static SSR时候有什么不同的。

如果哪里有错误,麻烦告之,谢谢谢谢!

相关推荐
暖馒4 小时前
Modbus应用层协议的深度剖析
网络·网络协议·c#·wpf·智能硬件
刘欣的博客8 小时前
C# CS架构程序发版升级的走数据库方案
c#·单文件升级自己的方式
Yorlen_Zhang9 小时前
Python Tkinter Text 控件完全指南:从基础编辑器到富文本应用
开发语言·python·c#
不绝1919 小时前
C#进阶:预处理指令/反射,Gettype,Typeof/关键类
开发语言·c#
大鹏说大话9 小时前
告别 MSBuild 脚本混乱:用 C# 和 Nuke 构建清晰、可维护的现代化构建系统
开发语言·c#
czhc114007566311 小时前
通信 28
c#
永远是我的最爱13 小时前
基于.NET的小小便利店前台收银系统
前端·sqlserver·.net·visual studio
菜鸟特工00714 小时前
javax.net.ssl.SSLPeerUnverifiedException 异常如何处理
网络协议·.net·ssl
bugcome_com14 小时前
C# 程序结构详解:从 Hello World 开始
c#
唐梓航-求职中15 小时前
编程-技术-算法-leetcode-288. 单词的唯一缩写
算法·leetcode·c#