Skip to content

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

@zzy

Description

@zzy

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions