DioxusLabs/dioxus · error · syn::Error
expected path to start with '/'
Error message
expected path to start with '/'
What it means
RouteParser::new requires the path portion of the route literal to start with `/` (packages/fullstack-macro/src/lib.rs:985-988). Without a leading slash the generated axum route would be relative/invalid, so the macro refuses it immediately.
Source
Thrown at packages/fullstack-macro/src/lib.rs:986
}
struct RouteParser {
path_params: Vec<(Slash, PathParam)>,
query_params: Vec<QueryParam>,
}
impl RouteParser {
fn new(lit: LitStr) -> syn::Result<Self> {
let val = lit.value();
let span = lit.span();
let split_route = val.split('?').collect::<Vec<_>>();
if split_route.len() > 2 {
return Err(syn::Error::new(span, "expected at most one '?'"));
}
let path = split_route[0];
if !path.starts_with('/') {
return Err(syn::Error::new(span, "expected path to start with '/'"));
}
let path = path.strip_prefix('/').unwrap();
let mut path_params = Vec::new();
for path_param in path.split('/') {
path_params.push((
Slash(span),
PathParam::new(path_param, span, Box::new(parse_quote!(())))?,
));
}
let path_param_len = path_params.len();
for (i, (_slash, path_param)) in path_params.iter().enumerate() {
match path_param {
PathParam::WildCard(_, _, _, _, _, _) => {
if i != path_param_len - 1 {
return Err(syn::Error::new(View on GitHub (pinned to 393d190a80)
Solutions
- Add the leading slash: `#[route(GET, "/items/{id}")]`.
- Double-check any route constants shared between client and server — the server macro always requires the slash.
- If the intent was a client-side page route, use dioxus-router's route macro instead of the fullstack one.
Example fix
// before
#[route(GET, "items/{id}")]
async fn item(id: i32) { ... }
// after
#[route(GET, "/items/{id}")]
async fn item(id: i32) { ... } Defensive patterns
Strategy: validation
Validate before calling
fn validate_route(route: &str) -> Result<(), String> {
let path = route.split('?').next().unwrap();
if !path.starts_with('/') {
return Err(format!("path must start with '/': {route}"));
}
Ok(())
} Prevention
- Never reuse dioxus-router client route strings verbatim in fullstack route attributes without checking the leading slash.
- Keep route strings in consts so a single test can validate them all.
When it happens
Trigger: `#[route(GET, "items/{id}")]`; `#[get("home")]`; building the string with `format!`-like composition in source and dropping the slash; porting a frontend Dioxus router route (which does not need a leading slash in some contexts) into a fullstack route attribute.
Common situations: Confusion between client-side `#[route]` (dioxus-router) and server-side fullstack `#[route]` conventions; typos; trimming slashes during copy-paste.
Related errors
- Use `api_route` instead of `route` to use OpenAPI options
- path parameter `{}` not found in function arguments
- query parameter `{}` not found in function arguments
- Cannot have multiple query parameters when one is a catch-al
- HTTP method specified both in macro and in attribute
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/6b42c7da5e7a3c2e.
Report an issue: GitHub.