diff --git a/docs/book/src/router/17_nested_routing.md b/docs/book/src/router/17_nested_routing.md index 854ec7d87..340ebbe57 100644 --- a/docs/book/src/router/17_nested_routing.md +++ b/docs/book/src/router/17_nested_routing.md @@ -153,6 +153,43 @@ pub fn ContactList() -> impl IntoView { } ``` +## Refactoring Route Definitions + +You don’t need to define all your routes in one place if you don’t want to. You can refactor any `` and its children out into a separate component. + +For example, you can refactor the example above to use two separate components: + +```rust +#[component] +fn App() -> impl IntoView { + view! { + + + + + "Select a contact to view more info."

+ }/> +
+
+
+ } +} + +#[component(transparent)] +fn ContactInfoRoutes() -> impl IntoView { + view! { + + + + + + } +} +``` + +This second component is a `#[component(transparent)]`, meaning it just returns its data, not a view: in this case, it's a [`RouteDefinition`](https://docs.rs/leptos_router/latest/leptos_router/struct.RouteDefinition.html) struct, which is what the `` returns. As long as it is marked `#[component(transparent)]`, this sub-route can be defined wherever you want, and inserted as a component into your tree of route definitions. + ## Nested Routing and Performance All of this is nice, conceptually, but again—what’s the big deal?