-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
A-yew-routerArea: The yew-router crateArea: The yew-router crateergonomicsfeature-requestA feature requestA feature requestproposal
Description
Nested routers allow users to separate parts of application.
API
I would like to have the following API:
#[derive(Routable)]
enum Route {
#[at("/")]
Home,
#[at("/room/:id")]
Room
}
// main component
html! { <Router<Routes> render=Router::render(main_switch) /> }
fn main_switch(route: &Route) -> Html {
match route {
Route::Home => html! { <Home /> },
Route::Room => html! { <Room /> },
}
}
// `Room` component
html! {
<Router<RoomRoutes> render=Router::render(room_render) />
}
#[derive(Routable)]
#[mount_at("/room")]
enum RoomRoute {
#[at("/")] // will be /room/
List,
#[at("/:id")] // will be /room/:id
View { id: u64 },
}
fn room_render(route: &RoomRoute) -> Html {
match route {
RoomRoute::List => html! { <ListRooms /> },
RoomRoute::View { id } => html! { <DisplayRoom id=id /> },
}
}
Implementation
In order to implement the aforementioned API, we would:
- Add a function
Routable
trait for handlingmount_at
fn mount_at() -> Option<&'static str>;
- Macro will implement this function, optionally returning a value
- Router and functions for handling routes will use this value in order to ensure the child router works properly
sveatlo, bhgomes, ctron, ya-mouse, richard-fairthorne and 1 more
Metadata
Metadata
Assignees
Labels
A-yew-routerArea: The yew-router crateArea: The yew-router crateergonomicsfeature-requestA feature requestA feature requestproposal