Code Monkey home page Code Monkey logo

yew-router's People

Contributors

anlumo avatar boscop avatar dependabot-preview[bot] avatar dependabot[bot] avatar jkelleyrtp avatar saschagrunert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yew-router's Issues

Unable to build yew-router without cargo-web

Basically, title.

I'm trying to build a simple web-app using yew (targeting wasm32-unknown-unknown). Right now I have a webpack-based build-system (more-or-less based on yew-wasm-pack-template).

Webpack wasm-pack-plugin, obviously, does not use cargo-web, but wasm-pack. And if I depend on yew-router in my Cargo.toml it fails during yew-router compilation with errors regarding js! macro.

I've fetched yew-router and tried to directy build it with cargo build --target wasm32-unknown-unknown and got the same errors. I've then installed cargo-web and successfully built it.

So, my questions is: Is it even possible to build yew-router without using cargo-web? Am I doing something wrong here?

Ideas for the future API

I think it would be cool if we could have routing like this (with a Router proc-macro):

#[derive(Router)]
enum AppRoute {
    #[at = "/"] // should be equivalent with ""
    Home,

    #[at = "/feed"] // route with no members
    Feed,

    #[at = "/profile/:user_id"]
    Profile { user_id: i64 }, // members matched to path segments by name

    #[at = "/foo/:name/:id"]
    Foo { name: String, id: i64 }, // multiple members matched to path segments by name

    #[at = "/post/:id"]
    Post(i64), // unnamed members also work

    #[at = "/bar/:name/:id"]
    Bar(String, i64), // even multiple unnamed members. number of members and :segments must be equal

    #[at = "/settings"] // factoring out sub-routes
    Settings(SettingsRoute),
}

#[derive(Router)]
enum SettingsRoute {
    #[at = "/notifications"] // absolute path will be /settings/notifications
    Notifications,

    #[at = "/privacy"] // absolute path will be /settings/privacy
    Privacy,
}

Switch to correct route upon pageload, based on initial URL

Currently, when the app is loaded, the Default route is active, even if the URL says otherwise.
E.g. you can see it in my example here: #213.
If the user came to the page by entering a certain url, we should route to it upon pageload.
Not sure what the best event to listen to is, for this.
E.g. there is DOMContentLoaded which fires before load (not waiting for assets to load).
Not sure if DOMContentLoaded will fire before our wasm app is started, and if we register a handler for it in the wasm app, if we still catch the event that was fired before..
Related:
https://stackoverflow.com/questions/2414750/difference-between-domcontentloaded-and-load-events
https://stackoverflow.com/questions/7745124/event-which-triggers-before-domcontentloaded

Deriving Clone, Copy in RouterTarget Would Help

Adding Clone, Copy to the #[derive] declaration generated by the routes macro would allow passing the enum values around in messages and be stored in components (for example for having a list of target routes for a menu). This would remove the need to list the routes multiple times in the code.

Example won't build

Tried to build minimal.rs example with yew 0.8.
Cargo.toml

[package]
name = "minimal"
version = "0.1.0"
edition = "2018"

[dependencies]
yew = "0.8"
yew-router = "*"

Result:

error[E0599]: no function or associated item named `bridge` found for type `yew_router::RouterAgent<_>` in the current scope
  --> src\main.rs:46:26
   |
46 |             RouterAgent::bridge(link.send_back(PageActions::Route));
   |                          ^^^^^^ function or associated item not found in `yew_router::RouterAgent<_>`
   |
   = note: the method `bridge` exists but the following trait bounds were not satisfied:
           `&mut yew_router::RouterAgent<_> : yew::agent::Bridged`
           `&yew_router::RouterAgent<_> : yew::agent::Bridged`
           `yew_router::RouterAgent<_> : yew::agent::Bridged`
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
   |
5  | use yew::agent::Bridged;
   |

error[E0277]: the trait bound `yew_router::RouterAgent<()>: yew::agent::Agent` is not satisfied
  --> src\main.rs:61:18
   |
61 |                 .send(yew_router::Request::ChangeRoute(pageroute)),
   |                  ^^^^ the trait `yew::agent::Agent` is not implemented for `yew_router::RouterAgent<()>`
warning: unused import: `Bridged`
 --> src\main.rs:6:19
  |
6 |     html, Bridge, Bridged, Component, ComponentLink, Html, Renderable,
  |                   ^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default
error: Could not compile `route`.
error: aborting due to 2 previous errors

Example builds fine with yew 0.7

yew-router no longer works against github yew

For instance, building your webapp.rs, modifying the Cargo.toml in the frontend directory so that under dependencies:

yew = { git = "https://github.com/DenisKolodin/yew", features = ["cbor"] }

Now if I run clippy it fails to build:

$ make lint-clippy
   Compiling webapp-frontend v1.0.0 (/Users/mahakal/Development/Apps/webapp.rs/frontend)
error[E0599]: no function or associated item named `bridge` found for type `yew_router::router::RouterAgent<_>` in the current scope
  --> frontend/src/component/content.rs:47:45
   |
47 |         let mut router_agent = RouterAgent::bridge(link.send_back(|_| Message::Ignore));
   |                                             ^^^^^^ function or associated item not found in `yew_router::router::RouterAgent<_>`
   |
   = note: the method `bridge` exists but the following trait bounds were not satisfied:
           `&mut yew_router::router::RouterAgent<_> : yew_shared::agent::Bridged`
           `&yew_router::router::RouterAgent<_> : yew_shared::agent::Bridged`
           `yew_router::router::RouterAgent<_> : yew_shared::agent::Bridged`
   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
           `use yew::agent::Bridged;`

error[E0277]: the trait bound `yew_router::router::RouterAgent<()>: yew_shared::agent::Agent` is not satisfied
  --> frontend/src/component/content.rs:98:26
   |
98 |                         .send(yew_router::Request::ChangeRoute(RouterTarget::Login.into()));
   |                          ^^^^ the trait `yew_shared::agent::Agent` is not implemented for `yew_router::router::RouterAgent<()>`

error[E0277]: the trait bound `yew_router::router::RouterAgent<()>: yew_shared::agent::Agent` is not satisfied
   --> frontend/src/component/content.rs:124:22
    |
124 |                     .send(yew_router::Request::ChangeRoute(RouterTarget::Login.into()));
    |                      ^^^^ the trait `yew_shared::agent::Agent` is not implemented for `yew_router::router::RouterAgent<()>`

error[E0599]: no function or associated item named `bridge` found for type `yew_router::router::RouterAgent<_>` in the current scope
  --> frontend/src/component/login.rs:59:40
   |
59 |             router_agent: RouterAgent::bridge(link.send_back(|_| Message::Ignore)),
   |                                        ^^^^^^ function or associated item not found in `yew_router::router::RouterAgent<_>`
   |
   = note: the method `bridge` exists but the following trait bounds were not satisfied:
           `&mut yew_router::router::RouterAgent<_> : yew_shared::agent::Bridged`
           `&yew_router::router::RouterAgent<_> : yew_shared::agent::Bridged`
           `yew_router::router::RouterAgent<_> : yew_shared::agent::Bridged`
   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
           `use yew::agent::Bridged;`

error[E0277]: the trait bound `yew_router::router::RouterAgent<()>: yew_shared::agent::Agent` is not satisfied
   --> frontend/src/component/login.rs:117:47
    |
117 |                             self.router_agent.send(yew_router::Request::ChangeRoute(
    |                                               ^^^^ the trait `yew_shared::agent::Agent` is not implemented for `yew_router::router::RouterAgent<()>`

error[E0599]: no function or associated item named `bridge` found for type `yew_router::router::RouterAgent<_>` in the current scope
  --> frontend/src/component/root.rs:45:45
   |
45 |         let mut router_agent = RouterAgent::bridge(link.send_back(Message::Route));
   |                                             ^^^^^^ function or associated item not found in `yew_router::router::RouterAgent<_>`
   |
   = note: the method `bridge` exists but the following trait bounds were not satisfied:
           `&mut yew_router::router::RouterAgent<_> : yew_shared::agent::Bridged`
           `&yew_router::router::RouterAgent<_> : yew_shared::agent::Bridged`
           `yew_router::router::RouterAgent<_> : yew_shared::agent::Bridged`
   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
           `use yew::agent::Bridged;`

error[E0277]: the trait bound `yew_router::router::RouterAgent<()>: yew_shared::agent::Agent` is not satisfied
  --> frontend/src/component/root.rs:99:47
   |
99 |                             self.router_agent.send(yew_router::Request::ChangeRoute(
   |                                               ^^^^ the trait `yew_shared::agent::Agent` is not implemented for `yew_router::router::RouterAgent<()>`

error[E0277]: the trait bound `yew_router::router::RouterAgent<()>: yew_shared::agent::Agent` is not satisfied
   --> frontend/src/component/root.rs:109:34
    |
109 |                                 .send(yew_router::Request::ChangeRoute(RouterTarget::Login.into()));
    |                                  ^^^^ the trait `yew_shared::agent::Agent` is not implemented for `yew_router::router::RouterAgent<()>`

error[E0277]: the trait bound `yew_router::router::RouterAgent<()>: yew_shared::agent::Agent` is not satisfied
   --> frontend/src/component/root.rs:117:26
    |
117 |                         .send(yew_router::Request::ChangeRoute(RouterTarget::Login.into()));
    |                          ^^^^ the trait `yew_shared::agent::Agent` is not implemented for `yew_router::router::RouterAgent<()>`

error: unused import: `agent::Bridged`
  --> frontend/src/component/root.rs:19:11
   |
19 | use yew::{agent::Bridged, format::Cbor, html, prelude::*, services::fetch::FetchTask};
   |           ^^^^^^^^^^^^^^
   |
   = note: `-D unused-imports` implied by `-D warnings`

error: aborting due to 10 previous errors

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.