feat: wrap frontend routes in FrontendLayout via router #[layout] attribute

- All public-facing pages (Home, Archives, Tags, PostDetail, Search,
  About, HomePage) are now wrapped in #[layout(FrontendLayout)]
- Header and Footer stay mounted during page transitions, only the
  <Outlet> content swaps — eliminates full-page flash/flicker
- Login and Register routes moved outside FrontendLayout since they
  are standalone pages without navigation header
- Route order restructured: FrontendLayout block → admin nest → auth pages
- Note: #[end_layout]/#[end_nest] must have a variant after them in the
  enum, otherwise the Routable derive macro fails with 'expected identifier'
This commit is contained in:
xfy 2026-06-03 18:35:36 +08:00
parent e861b8a5be
commit 8845577958

View File

@ -2,6 +2,7 @@ use dioxus::prelude::*;
use std::sync::Arc;
use crate::components::admin_layout::AdminLayout;
use crate::components::frontend_layout::FrontendLayout;
use crate::context::UserContext;
use crate::pages::about::About;
use crate::pages::admin::{Admin, Posts, Write};
@ -17,14 +18,24 @@ use crate::theme::{use_theme_provider, Theme, ThemePreload};
#[derive(Clone, Routable, Debug, PartialEq)]
#[rustfmt::skip]
pub enum Route {
#[route("/")]
Home {},
#[route("/page/:page")]
HomePage { page: i32 },
#[route("/login")]
Login {},
#[route("/register")]
Register {},
#[layout(FrontendLayout)]
#[route("/")]
Home {},
#[route("/page/:page")]
HomePage { page: i32 },
#[route("/archives")]
Archives {},
#[route("/tags")]
Tags {},
#[route("/tags/:tag")]
TagDetail { tag: String },
#[route("/post/:slug")]
PostDetail { slug: String },
#[route("/search")]
Search {},
#[route("/about")]
About {},
#[end_layout]
#[nest("/admin")]
#[layout(AdminLayout)]
@ -37,18 +48,10 @@ pub enum Route {
#[end_layout]
#[end_nest]
#[route("/archives")]
Archives {},
#[route("/tags")]
Tags {},
#[route("/tags/:tag")]
TagDetail { tag: String },
#[route("/post/:slug")]
PostDetail { slug: String },
#[route("/search")]
Search {},
#[route("/about")]
About {},
#[route("/login")]
Login {},
#[route("/register")]
Register {},
}
#[component]