-
-
Notifications
You must be signed in to change notification settings - Fork 936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Routable
improvements
#1461
Routable
improvements
#1461
Conversation
I can't think of a good usecase for these methods. The route enum is an instance of the route. It is a specific route, not the template from which routes can be made from (the site map). All of these methods return a instance of the route, not the route definition. For static routes, both the instance of a specific route and the route template are the same because there are no dynamic parameters. The way the code is structured currently, it looks like the dynamic parameters are filled in with the name of the dynamic parameter. This can cause parsing the route to behave unexpectedly. For example, this code: #![allow(non_snake_case)]
use dioxus::prelude::*;
use dioxus_router::prelude::*;
fn main() {
dioxus_web::launch(App);
}
#[derive(Routable, Clone, Debug)]
enum Route {
#[route("/")]
Home {},
#[route("/:id")]
TakesU64 { id: u64 },
#[route("/:string")]
TakesString { string: String },
#[route("/:..route")]
TakesSpread {
route: Vec<String>,
},
}
fn App(cx: Scope) -> Element {
render! {
Router::<Route> {}
}
}
fn Home(cx: Scope) -> Element {
render! {
h1 { "Welcome to the Dioxus Blog!" }
pre {
"all_routes:\n{Route::all_routes():?}"
}
pre {
"static_routes:\n{Route::static_routes():?}"
}
pre {
"dynamic_routes:\n{Route::dynamic_routes():?}"
}
pre {
"catch_all_routes:\n{Route::catch_all_routes():?}"
}
}
}
fn Blog(cx: Scope) -> Element {
todo!()
}
#[inline_props]
fn TakesString(cx: Scope, string: String) -> Element {
todo!()
}
#[inline_props]
fn TakesU64(cx: Scope, id: u64) -> Element {
todo!()
}
#[inline_props]
fn TakesSpread(cx: Scope, route: Vec<String>) -> Element {
render! {
h1 { "Page not found" }
p { "We are terribly sorry, but the page you requested doesn't exist." }
pre {
color: "red",
"log:\nattemped to navigate to: {route:?}"
}
}
}
|
I've changed them to instead return the definition. I can't test it because I get an error for
I'm surprised it works for you. I have the same exact code in a clean project as you, but still. |
You need to make the source of the dioxus, dioxus-web, and dioxus-router crates to all match. (in this case have them all point to the same git repo or local workspace) |
Thanks. It returns the name of the parameter, not the actual route.
Not sure if that's useful... |
Yeah, I don't think it is very useful. We could either remove those functions or return |
Removed them. Should be ready to merge when the checks complete. |
Routable::static_routes()
always produces an empty result #1451. Should also be a bit faster now.Routable
. These are:Routable::static_routes()
:all_routes() -> Vec<Routable>
dynamic_routes() -> Vec<Routable>
catch_all_routes() -> Vec<Routable>
flatten_site_map<'a>() -> SiteMapFlattened<'a>
- Returns a flattened version ofSelf::SITE_MAP
.