pub trait RouterExt<B>: Sealed {
    fn with<T>(self, routes: T) -> Self
    where
        T: HasRoutes<B>
; }
Expand description

Extension trait that adds additional methods to Router.

Required methods

Add the routes from T’s HasRoutes::routes to this router.

Example

Using Resource which implements HasRoutes:

use axum::{Router, routing::get};
use axum_extra::routing::{RouterExt, Resource};

let app = Router::new()
    .with(
        Resource::named("users")
            .index(|| async {})
            .create(|| async {})
    )
    .with(
        Resource::named("teams").index(|| async {})
    );

Implementations on Foreign Types

Implementors