Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it a bug for multiple parameters in development version ? #1987

Closed
zzy opened this issue Aug 4, 2021 · 4 comments · Fixed by #1988
Closed

Is it a bug for multiple parameters in development version ? #1987

zzy opened this issue Aug 4, 2021 · 4 comments · Fixed by #1988
Labels

Comments

@zzy
Copy link

zzy commented Aug 4, 2021

Problem
In-development version of yew-router, it doesn't work for defining multiple parameters.

Route enum

#[derive(Routable, PartialEq, Clone, Debug)]
pub enum Routes {
    ...
    #[at("/:username/:article_slug")]
    Article { username: String, article_slug: String }, // error: expected one of `,`, `.`, `?`, `}`, or an operator, 
                                                        // found `article_slug`
    #[at("/category/:category_slug")]
    Category { category_slug: String },
    #[at("/topic/:topic_slug")]
    Topic { topic_slug: String },
    ...
}

switch function

pub fn switch(goal: &Routes) -> Html {
    match goal {
        ...
        Routes::Author { username } => {
            html! { <Author username={username.clone()} /> }
        }
        Routes::Article { username, article_slug } => {
            html! { <Article username={username.clone()} article_slug={article_slug.clone()} /> }
        }
        Routes::Category { category_slug } => {
            html! { <Category category_slug={category_slug.clone()} /> }
        }
        Routes::Topic { topic_slug } => {
            html! { <Topic topic_slug={topic_slug.clone()} /> }
        }
        ...
    }
}

Article component

use yew::prelude::*;

#[derive(Clone, Debug, Eq, PartialEq, Properties)]
pub struct Props {
    pub username: String,
    pub article_slug: String,
}

pub struct Article;

impl Component for Article {
    type Message = ();
    type Properties = Props;

    fn create(_props: Self::Properties, _link: ComponentLink<Self>) -> Self {
    ...
    ...
    ...
    }
}

Environment:

  • Yew version: master
  • Rust version: 1.54.0
  • Target, if relevant: wasm32-unknown-emscripten
  • Build tool, if relevant: trunk
  • OS, if relevant: Windows / MacOS
  • Browser and version, if relevant: Firefox v90.0.2 / Safari

Thank you very much!

@zzy zzy added the bug label Aug 4, 2021
@zzy
Copy link
Author

zzy commented Aug 4, 2021

@mc1098 Thank you very much !

@mc1098
Copy link
Contributor

mc1098 commented Aug 4, 2021

@zzy Thank you for the detailed issue :D
I think the CI failed due to an error getting rustc but I think this fix should be merged shortly 🙏
I did test the change on the router example to confirm it works at runtime too :)

@zzy
Copy link
Author

zzy commented Aug 4, 2021

@zzy Thank you for the detailed issue :D
I think the CI failed due to an error getting rustc but I think this fix should be merged shortly 🙏
I did test the change on the router example to confirm it works at runtime too :)

@mc1098 Good job! Thank you.

@zzy zzy closed this as completed Aug 4, 2021
@mc1098
Copy link
Contributor

mc1098 commented Aug 4, 2021

@zzy Can you reopen this issue? :)
Let #1988 close the issue - just in case that PR needs more work it allows others to see the issue hasn't been fixed until that PR is merged into master

@zzy zzy reopened this Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants