Update Yew Router as per #2113#2118
Merged
Merged
Conversation
# Conflicts: # packages/yew-router/src/components/redirect.rs # packages/yew-router/src/lib.rs
|
Visit the preview URL for this PR (updated for commit 4621208): https://yew-rs--pr2118-yew-router-proposal-nl2t2n44.web.app (expires Thu, 28 Oct 2021 11:16:49 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
voidpumpkin
requested changes
Oct 21, 2021
Comment on lines
84
to
113
| // #[derive(Serialize, Clone)] | ||
| // struct QueryParams { | ||
| // foo: String, | ||
| // bar: u32, | ||
| // } | ||
|
|
||
| // #[test] | ||
| // fn test_get_query_params() { | ||
| // assert_eq!( | ||
| // parse_query::<HashMap<String, String>>().unwrap(), | ||
| // HashMap::new() | ||
| // ); | ||
|
|
||
| // let query = QueryParams { | ||
| // foo: "test".to_string(), | ||
| // bar: 69, | ||
| // }; | ||
|
|
||
| // yew_router::push_route_with_query(Routes::Home, query).unwrap(); | ||
|
|
||
| // let params: HashMap<String, String> = parse_query().unwrap(); | ||
|
|
||
| // assert_eq!(params, { | ||
| // let mut map = HashMap::new(); | ||
| // map.insert("foo".to_string(), "test".to_string()); | ||
| // map.insert("bar".to_string(), "69".to_string()); | ||
| // map | ||
| // }); | ||
| // } | ||
| } |
Member
There was a problem hiding this comment.
Why are these tests commented out?
Member
Author
There was a problem hiding this comment.
parse_query and push_route_with_query are replaced by location.query() and history.push_with_query().
You can find the updated test here: https://github.com/yewstack/yew/pull/2118/files#diff-ec64ea4b4e8cbcfcfc72c33eec28309e23f5f32be356f9a0ebc6068c1938d936R41
I just forgot to remove the old test, will do shortly.
18 tasks
voidpumpkin
approved these changes
Nov 8, 2021
siku2
approved these changes
Nov 11, 2021
Closed
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2113, #2116
Supersedes the first section of #1860.
This PR mainly makes
yew-routera little bit more likereact-router, it consists of the following changes:HistoryandLocationtraits to makeyew-routerSSR capable (MemoryHistory to be added.).historylocationandroute.RouterScopeExttrait to provide a way to accesshistory,locationandrouteand add listeners for struct component.yew_router::service(Replaced by hooks andRouterScopeExt).<Router />a context provider and Add<Switch />component to dispatch between routes.<Redirect />component that mirrors the behaviour ofreact-router's<Redirect />component.routeprop onLinkcomponent toto.Defaultif#[not_found]is present onRoutable.Things to be decided:
The current suggestion is to use
Yewduxinstead (mainly due to ergonomic concerns).However, it's possible to push multiple states with the same route but state differs which can be hard to distinguish if separated from history and it's easy to implement so I added them anyways (and using
ctx.link().history().state()should not be more difficult thanWithDispatchergonomic wise).LocationMost setters on location would cause the page to reload and
historypackage does not implement a setter on them.Not sure if we should follow this behaviour.
For now I have opted for
historypackage's behaviour which is making location to be read only.Checklist
cargo make pr-flow