Commit WIP on router

There are a few different changes in here that probably need to be picked
apart. I'm sure much of this is wrong.

* Fix missing `dyn` that compiler complained about in router.rs

* Make UseRoute store a `Rc<RouterService>` rather than a string so we can get
information out of the router like current location.

* Implement `UseRoute`'s nth_segment and last_segment methods. I changed the
return type to a String because of the above.

* Remove some unused imports in platform/mod.rs and service.rs

* Implement the `use_route` fn. It panics if called outside a Router { } (I
think). I think that makes sense.

* Add a `current_location` method to `RouterService` that returns the current
location. I needed this both for the `UseRoute` implementation and _also_ so I
could get at this in my webapp code. I think having some way to get this will
be useful for others, whether or not this exact API is used. In my case, I
want to compare the current path to the `to` path of a `Link` so I can use a
different class for that `Link` if it is the currently active page.
This commit is contained in:
Dave Rolsky committed 2022-01-13 12:21:06 -06:00
1 parent 3a5b417ad1
commit 3c6142fb9d
4 files changed
+40 -11

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ pub struct RouterProps<'a> {
children: Element<'a>,
#[props(default, strip_option)]
onchange: Option<&'a Fn(&'a str)>,
onchange: Option<&'a dyn Fn(&'a str)>,
}
#[allow(non_snake_case)]