How to get ancestor path from a nested router? #1854
Answered
by
davidpdrsn
dulguun0225
asked this question in
Q&A
-
I wanna redirect to one of my own paths without hardcoding what my ancestor path is. use std::net::SocketAddr;
use axum::{response::Redirect, routing::get, Router};
fn users_router() -> Router {
Router::new()
.route("/", get(|| async { "users index" }))
.route("/fallback", get(|| async { "users fallback"}))
// make it redirect without hardcoding /users part.
.fallback(|| async { Redirect::to("/users/fallback") })
}
#[tokio::main]
async fn main() {
let app = Router::new().nest("/users", users_router());
axum::Server::bind(&SocketAddr::from(([127, 0, 0, 1], 5000)))
.serve(app.into_make_service())
.await
.unwrap()
} Maybe I could pass ancestor path to the |
Beta Was this translation helpful? Give feedback.
Answered by
davidpdrsn
Mar 15, 2023
Replies: 1 comment 3 replies
-
This feels like something we should support. Do you wanna open an issue about it? |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
dulguun0225
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This feels like something we should support. Do you wanna open an issue about it?