yewstack / yew

Rust / Wasm framework for creating reliable and efficient web applications
https://yew.rs
Apache License 2.0
30.71k stars 1.42k forks source link

yew-router example does not compile #3547

Open AndreasBergmeier6176 opened 10 months ago

AndreasBergmeier6176 commented 10 months ago

This is about:

Problem

When copying https://yew.rs/docs/next/concepts/router into an editor, I get:

the trait bound `yew_router::Switch<Route>: yew::Component` is not satisfied
the trait `yew::Component` is implemented for `ContextProvider<T>`
required for `yew_router::Switch<Route>` to implement `yew::BaseComponent`

I use latest version of all packages.

Maybe it would be good to either always compile the example code as part of a release or be more specific with which versions that example code used to work.

ranile commented 10 months ago

Your versions are incorrect. All the examples are tested as part of CI run on every commit. Please show your Cargo.toml file

abergmeier commented 10 months ago
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
description = "Template for starting a Yew project using Trunk"
readme = "README.md"
repository = "https://github.com/yewstack/yew-trunk-minimal-template"
license = "MIT OR Apache-2.0"
keywords = ["yew", "trunk"]
categories = ["gui", "wasm", "web-programming"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde_json = "1.0.108"
yew = { version="0.21", features=["csr"] }
yew-router = { git = "https://github.com/yewstack/yew.git" }

What does seem to work though is using:

yew-router = "0.18.0"
ranile commented 10 months ago

You can't have mismatched versions. Either use both versions from crates.io or git. Yew from git is a different crate compared to 0.21 from crates.io and vice versa. yew-router from git depends on yew from git, so you can't have yew from crates.io there.

This is nothing that yew can do anything about. This is how Rust dependencies work

abergmeier commented 10 months ago

Note however, that https://yew.rs/docs/concepts/router indicates to simply add the git variant - which seems to be the wrong thing to do for most users IMO.

ranile commented 10 months ago

Would you like to PR a change for 0.21 docs?