Skip to content

404 with Query Parameter on / #2833

Closed Answered by abhillman
abhillman asked this question in Questions
Discussion options

You must be logged in to vote

Okay! The confusion I had is with the older docs, which are perhaps ambiguous.

I was able to fix this with the following:

#[macro_use] extern crate rocket;

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![index])
}

#[get("/?<name>")]
fn index(name: Option<&str>) -> String {
    if name.is_some() {
        format!("Hello, {}!", &name.unwrap())
    } else {
        "Hello, world!".to_string()
    }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@the10thWiz
Comment options

Answer selected by abhillman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants