ctron / yew-nested-router

A router for Yew supporting nesting
Apache License 2.0
6 stars 5 forks source link

Question on list and details route #17

Open AlexandreRoba opened 1 month ago

AlexandreRoba commented 1 month ago

Hi all, I'm trying to find a way to map routes that looks like this: -/directors/ map to director list -/directors/xxxxx map to the director details

I came up with something like this:

#[derive(Target, Debug, Clone, PartialEq, Eq, Display)]
pub enum DirectorsRoute {
    #[target(index)]
    Index,
    Details(#[target(value)] String),
}

But no matter what I do, I always have "details" in the path -/directors/ map to director list -/directors/details/xxxxx map to the director details

What would be the best way to acheive this? I found a way using something like this:

    Directors {
        director_id: String,
        #[target(nested)]
        target: DirectorRoute,
    },

pub enum DirectorRoute {
    #[target(index)]
    Index,
}

But then I need to pattern math with a gard where I check if the director_id is empty then display the list and if not display the details....

Is this the way? :p

ctron commented 1 month ago

Sorry for the late response. I just checked an I came up with the same solution.


pub enum App {
  #[target(index)]
  Index,
  Directors(Directors)
}

pub enum  Directors {
        director_id: String,
        #[target(nested)]
        target: DirectorRoute,
};

pub enum DirectorRoute {
    #[target(index)]
    Index,
}

The idea was that the value takes the first (local) segment. And thus would result in an empty value.

An alternative could be:

pub enum App {
  #[target(index)]
  Index,
  Directors
  #[target(rename="directors"]
  DirectorsWith{ id: String }
}