Crates.io | gpui-router-macros |
lib.rs | gpui-router-macros |
version | |
source | src |
created_at | 2025-03-25 08:49:11.903672+00 |
updated_at | 2025-03-25 08:49:11.903672+00 |
description | Router macros for gpui |
homepage | https://github.com/justjavac/gpui-router |
repository | https://github.com/justjavac/gpui-router |
max_upload_size | |
id | 1604989 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A router for GPUI App, inspired by React-Router.
[!WARNING] Warning: gpui-router is currently under active development. This library may contain experimental features and is subject to breaking changes in future releases.
use gpui::prelude::*;
use gpui::{App, Application, Context, Window, WindowOptions, div};
use gpui_router::{NavLink, Outlet, Route, Routes, init as router_init};
struct HelloWorld {}
impl Render for HelloWorld {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div()
.child(
Routes::new().child(
Route::new().path("/").element(layout()).children(vec![
Route::new().index().element(home()),
Route::new().path("about").element(about()),
Route::new().path("dashboard").element(dashboard()),
Route::new().path("{*not_match}").element(not_match()),
]),
),
)
}
}
fn layout() -> impl IntoElement {
div()
.child(NavLink::new().to("/").child(div().child("Home")))
.child(NavLink::new().to("/about").child(div().child("About")))
.child(NavLink::new().to("/dashboard").child(div().child("Dashboard")))
.child(NavLink::new().to("/nothing-here").child(div().child("Not Match")))
.child(Outlet::new())
}
fn home() -> impl IntoElement {
div().child("Home")
}
fn about() -> impl IntoElement {
div().child("About")
}
fn dashboard() -> impl IntoElement {
div().child("Dashboard")
}
fn not_match() -> impl IntoElement {
div()
.child(div().child("Nothing to see here!"))
.child(NavLink::new().to("/").child(div().child("Go to the home page")))
}
fn main() {
Application::new().run(|cx: &mut App| {
router_init(cx);
cx.activate(true);
cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_cx| HelloWorld {}))
.unwrap();
});
}