Symptom#
The program panics at start-up, while the router is being built:
thread 'main' (43060) panicked at examples\f04.rs:7:38:
Path segments must not start with `:`. For capture groups, use `{capture}`. If you meant to literally match a segment starting with a colon, call `without_v07_checks` on the router.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtraceIt comes from code like this:
use axum::{extract::Path, routing::get, Router};
async fn show(Path(id): Path<u32>) -> String { format!("user {id}") }
#[tokio::main]
async fn main() {
let _app: Router = Router::new().route("/users/:id", get(show));
println!("router built");
}Cause#
Axum 0.8 uses {name} for a parameter and {*name} for a wildcard. The older :name and *name forms from axum 0.7 and earlier are rejected when the route is added, so the mistake shows at start-up and not on the first request.
Fix#
Router::new().route("/users/{id}", get(show)); // was "/users/:id"
Router::new().route("/files/{*path}", get(rest)); // was "/files/*path"If a path really contains a literal segment that starts with a colon, the panic message names the way out: call without_v07_checks on the router.
Common mistakes#
- Fixing one route and stopping. The panic names the file and line of the first bad route only, so run again after each fix until the router builds.
- Copying a tutorial written for axum 0.6 or 0.7. Check the axum version in the tutorial against your
Cargo.toml.
Related questions#
Is the change only for paths?#
This thread covers only paths. Other 0.8 changes are listed in the axum changelog.
Sources#
- axum changelog: https://github.com/tokio-rs/axum/blob/main/axum/CHANGELOG.md (read 2026-12-05)
- axum,
Router: https://docs.rs/axum/0.8.9/axum/struct.Router.html (read 2026-12-05)