leptos-rs / leptos

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

Compile error with refactored routes #3244

Closed bobhy closed 2 hours ago

bobhy commented 2 hours ago

Describe the bug Trying to refactor some <Route>s out into a transparent component, as shown in the book. Hitting compilation errors:

mentioned on discord

Leptos Dependencies

[workspace.dependencies]
leptos = { version = "0.7.0-rc1", features = ["ssr", "hydrate", "nightly"] }
leptos_meta = { version = "0.7.0-rc1" }
leptos_router = { version = "0.7.0-rc1", features = ["nightly"] }
leptos_axum = { version = "0.7.0-rc1" }

To Reproduce

  1. start with example of https://book.leptos.dev/router/17_nested_routing.html#refactoring-route-definitions
  2. make minimal porting changes for 0.7 (hopefully!)
  3. cargo build

Expected behavior Should compile.

Screenshots Actual code (test.rs)

use leptos::prelude::*;
use leptos_router::components::*;

#[component]
fn App() -> impl IntoView {
  view! {
    <Router>
      <Routes fallback=|| "Page not found.".into_view()>
        <Route path="/contacts" view=|| "contact list".into_view()>
          <ContactInfoRoutes/>
          <Route path="" view=|| view! {
            <p>"Select a contact to view more info."</p>
          }/>
        </Route>
      </Routes>
    </Router>
  }
}

#[component(transparent)]
fn ContactInfoRoutes() -> impl IntoView {
  view! {
    <Route path=":id" view=|| "anon".into_view()>
      <Route path="" view=|| "anon".into_view()/>
      <Route path="address" view=|| "anon".into_view()/>
      <Route path="messages" view=|| "anon".into_view()/>
    </Route>
  }
}

Errors:

error[E0599]: no method named `children` found for struct `RoutePropsBuilder` in the current scope
  --> app/src/test.rs:6:3
   |
6  |     view! {
   |  ___^
7  | |     <Router>
8  | |       <Routes fallback=|| "Page not found.".into_view()>
9  | |         <Route path="/contacts" view=|| "contact list".into_view()>
...  |
16 | |     </Router>
17 | |   }
   | |___^ method not found in `RoutePropsBuilder<&str, {closure@test.rs:9:38}, (..., ..., ...)>`
   |
   = note: the full type name has been written to '/home/bobhy/src/rustgui/db1/target/debug/deps/app-27b6d6e01d81c903.long-type-7858237838013196093.txt'
   = note: consider using `--verbose` to print the full type name to the console
   = note: this error originates in the macro `view` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `children` found for struct `RoutePropsBuilder` in the current scope
  --> app/src/test.rs:22:3
   |
22 |     view! {
   |  ___^
23 | |     <Route path=":id" view=|| "anon".into_view()>
24 | |       <Route path="" view=|| "anon".into_view()/>
25 | |       <Route path="address" view=|| "anon".into_view()/>
26 | |       <Route path="messages" view=|| "anon".into_view()/>
27 | |     </Route>
28 | |   }
   | |___^ method not found in `RoutePropsBuilder<&str, {closure@test.rs:23:28}, (..., ..., ...)>`
   |
   = note: the full type name has been written to '/home/bobhy/src/rustgui/db1/target/debug/deps/app-27b6d6e01d81c903.long-type-5811023363139442564.txt'
   = note: consider using `--verbose` to print the full type name to the console
   = note: this error originates in the macro `view` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `leptos::prelude::View<NestedRoute<_, (), (), _>>: leptos::IntoView` is not satisfied
  --> app/src/test.rs:21:27
   |
21 | fn ContactInfoRoutes() -> impl IntoView {
   |                           ^^^^^^^^^^^^^ the trait `RenderHtml` is not implemented for `leptos::prelude::View<NestedRoute<_, (), (), _>>`
   |
   = help: the trait `RenderHtml` is implemented for `leptos::prelude::View<T>`
   = note: required for `leptos::prelude::View<NestedRoute<_, (), (), _>>` to implement `leptos::IntoView`

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.

Additional context Add any other context about the problem here.

benwis commented 2 hours ago

Yeah, this isn't a Github issue, that's a valid error message. The way Router works and how to define paths has changed dramatically in 0.7: For example, see below: https://github.com/leptos-rs/leptos/blob/1c26261fd71a027e7ed46676eb147ba814ebca38/examples/hackernews_axum/src/lib.rs#L39