Skip to main content

Module post_detail

Module post_detail 

Source
Expand description

文章详情页面模块。

对应路由 /post/:slug

数据获取:通过 use_server_future 调用 get_post_by_slug server function, 根据 URL 中的 slug 获取单篇文章详情(含正文 HTML、目录、封面及上下篇导航)。

§反应式取数的关键

Dioxus 0.7 的 use_server_future(内部即 use_resource)只在闭包内读取的 signal 变化时才会重跑 future——它通过 ReactiveContext 追踪闭包执行期间的 订阅。但本组件的 slug 是路由宏注入的普通 String prop,被 move 进闭包后 成了冻结快照,读取它不会建立订阅。因此上/下一篇导航(同一路由变体间的 slug 变化)会复用组件实例、更新 props,却无法触发 future 重跑——表现为「URL 变了 但内容不变,刷新才生效」。

修复:在闭包内通过 router().current::<Route>() 读取当前 slug。current() 内部调用 subscribe_to_current_context(),在 use_server_future 的 ReactiveContext 中注册订阅;路由变化时订阅触发,future 自动重跑。 在 wasm32 目标下,server function 的函数体被替换为向服务端端点发起 HTTP POST 请求的客户端存根; 实际的数据库访问逻辑仅在 feature = "server" 启用时运行。

Re-exports§

pub use PostDetail_completions::Component::PostDetail;

Structs§

PostDetailProps
Properties for the PostDetail component.

Functions§

PostDetail
文章详情页面组件,对应路由 /post/:slug