Skip to main content

NotFound

Function NotFound 

Source
pub fn NotFound(_: NotFoundProps) -> Element
Expand description

404 页面组件,对应兜底路由 /:..segments

展示大号的装饰性 404 数字、状态标签、错误说明以及返回首页的链接。

§两种命中路径

本组件在两种完全不同的机制下被渲染:

  1. 路由匹配 —— 访问任意未命中路径,Router 命中 catch-all Route::NotFound, 此时 ErrorBoundary 无错误,本组件作为 children(Outlet)正常渲染。
  2. 错误冒泡 —— 如 PostDetail 对不存在的 slug 抛出 ServerFnError(404)ErrorLayoutErrorBoundary 捕获后在 fallback 里渲染本组件。

「返回首页」必须在导航前清除可能存在的错误边界,否则场景 2 会卡死: ErrorBoundary 持有错误时不渲染 children(Outlet),路由虽切到 Home, 页面仍停留在 fallback(本组件),表现为「URL 变了但页面不变」。 场景 1 下没有错误,clear_errors 是 no-op。

§Props

For details, see the props struct definition.