1 unstable release

0.1.0 Apr 24, 2024

#795 in Web programming

Download history 150/week @ 2024-04-22

150 downloads per month

MIT license

6KB
69 lines

🍫 Fracter

Fragment hash based router, for Sycamore

Live demo

Fracter trait will be default implemented for Isomorphism + Default + PartialEq implemented enum type.

Supports Sycamore version 0.9.0 or later.

Ex

use sycamore::prelude::*;
use fracter::{Fracter, Isomorphism};

#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Isomorphism)]
#[isomorphism(list=[Index, Notice, Contact])]
pub enum Fragment {
  #[default] Index,
  Notice,
  Contact
}

#[component]
pub fn App<G: Html>() -> View<G> {

  // `init` will handle everything: captures hash change, updates history, etc.
  let fragment = Fragment::init();

  view! {
    main() {
      // Use fragment as if router
      (match fragment.get() {
        Fragment::Notice => view! { "📢 Notice" },
        Fragment::Contact => view! { "🔭 Contact" },
        _ => view! { "✅ Index" },
      })
    }
  }
}

Dependencies

~12MB
~220K SLoC