leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
15.28k stars 599 forks source link

[0.7-alpha] `<Route ... view=Component/>` fails if `Component` has an optional prop #2659

Closed bicarlsen closed 5 days ago

bicarlsen commented 5 days ago

<Route ... view=Component/> fails if Component has an optional prop, but <Route ... view=view! { <Component/> }/> works.

<Router>
  <Routes fallback=|| "An error occurred">
    <Route path=StaticSegment("") view=Count/> // Errors
    <Route path=StaticSegment("") view=move || view! { <Count/> }/> // Works
  </Routes>
<Router>

#[component]
fn Register(#[prop(default = 0)] count: usize) -> impl IntoView {
...
}

Leptos Dependencies

leptos = { git = "https://github.com/leptos-rs/leptos.git", branch = "leptos_0.7", features = ["csr", "nightly"] }
leptos_router = { git = "https://github.com/leptos-rs/leptos.git", branch =  "leptos_0.7", features = ["nightly"] }

To Reproduce See example above.

Expected behavior Optional props will be set to their default value.

Screenshots N/A

Additional context N/A

gbj commented 5 days ago

This is true on all versions and working as designed -- view takes a function with no arguments, and a component is only a function of no arguments if it has no props. Otherwise it is a function of one argument, the struct of props. Register has one prop (not zero), so it is a function of one argument (the props struct), not zero.