Problem
The nested routers are failing to match URLs with specific patterns.
* did not catch the empty string.
Steps To Reproduce
- Implement the code:
use yew::prelude::*;
use yew_router::prelude::*;
#[derive(Clone, Routable, PartialEq)]
enum MainRoute {
#[at("/")]
Home,
#[at("/news")]
News,
#[at("/contact")]
Contact,
#[at("/settings/*")]
Settings,
#[not_found]
#[at("/404")]
NotFound,
}
#[derive(Clone, Routable, PartialEq)]
enum SettingsRoute {
#[at("/settings")]
Profile,
#[at("/settings/some/friends")]
Friends,
#[at("/settings/")]
Theme,
#[not_found]
#[at("/settings/404")]
NotFound,
}
fn switch_main(route: &MainRoute) -> Html {
match route {
MainRoute::Home => html! {<h1>{"Home"}</h1>},
MainRoute::News => html! {<h1>{"News"}</h1>},
MainRoute::Contact => html! {<h1>{"Contact"}</h1>},
MainRoute::Settings => html! {
<Switch<SettingsRoute> render={Switch::render(switch_settings)} />
},
MainRoute::NotFound => html! {<h1>{"Not Found"}</h1>},
}
}
fn switch_settings(route: &SettingsRoute) -> Html {
match route {
SettingsRoute::Profile => html! {<h1>{"Profile"}</h1>},
SettingsRoute::Friends => html! {<h1>{"Friends"}</h1>},
SettingsRoute::Theme => html! {<h1>{"Theme"}</h1>},
SettingsRoute::NotFound => html! {
<Redirect<MainRoute> to={MainRoute::NotFound}/>
}
}
}
#[function_component(App)]
pub fn app() -> Html {
html! {
<BrowserRouter>
<Switch<MainRoute> render={Switch::render(switch_main)} />
</BrowserRouter>
}
}
fn main() {
yew::start_app::<App>();
}
- Go to
localhost:8080/settings/some/friends
- See
Friends
- Go to
localhost:8080/settings/
- See error
- Go to
localhost:8080/settings
- See error
Expected behavior
- Go to
localhost:8080/settings/some/friends
- See
Friends
- Go to
localhost:8080/settings/
- See
Theme
- Go to
localhost:8080/settings
- See
Not Found
Environment:
- Yew version: 0.19.3
- Rust version: 1.63.0
- Target, if relevant:
wasm32-unknown-unknown
- Build tool, if relevant:
trunk
- OS, if relevant: MacOS
- Browser and version, if relevant: Chrome v 104.0.5112.101
Questionnaire
Problem
The nested routers are failing to match URLs with specific patterns.
*did not catch the empty string.Steps To Reproduce
localhost:8080/settings/some/friendsFriendslocalhost:8080/settings/localhost:8080/settingsExpected behavior
localhost:8080/settings/some/friendsFriendslocalhost:8080/settings/Themelocalhost:8080/settingsNot FoundEnvironment:
wasm32-unknown-unknowntrunkQuestionnaire