Skip to content

Commit 274d8c5

Browse files
committed
Href-based routing API now works beyond the first nest-level.
1 parent 31b10cf commit 274d8c5

File tree

4 files changed

+14
-37
lines changed

4 files changed

+14
-37
lines changed

.gitignore

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ workspace.xml
99
*.wasm
1010
# Allow JS in example folders
1111
# wasm-bindgen won't automatically create this directory.
12-
<<<<<<< HEAD
1312
# **/pkg/*
1413
**/.wasm
1514
**.d.ts
@@ -18,11 +17,4 @@ workspace.xml
1817
**/node_modules/
1918
**/target/
2019
**.log
21-
=======
22-
# pkg/
23-
*.d.ts
24-
*.ts
25-
*.js
26-
node_modules/
27-
*.log
28-
>>>>>>> e449e6645f76720a29d6dfa7971198381acc247c
20+

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v0.2.10
4+
- Routing can be triggered by clicking any element containing a `Href` attribute
5+
with value as a relative link
6+
- Internal links no longer trigger a page refresh
7+
- Models no longer need to implement `Clone`
8+
- Fixed a bug introduced in 0.2.9 for `select` elements
9+
310
## v0.2.9
411
- Added a `RenderThen` option to `Update`, which allows chaining update messages
512
- Added a `.model` method to `Update`, allowing for cleaner recursion in updates

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "seed"
3-
version = "0.2.9"
3+
version = "0.2.10"
44
description = "A Rust framework for creating web apps, using WebAssembly"
55
authors = ["DavidOConnor <[email protected]>"]
66
license = "MIT"

src/routing.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -107,32 +107,10 @@ where
107107
app
108108
}
109109

110-
<<<<<<< HEAD
110+
111111
fn remove_first(s: &str) -> Option<&str> {
112112
s.chars().next().map(|c| &s[c.len_utf8()..])
113113
}
114-
=======
115-
pub fn setup_popstate_listener<Ms, Mdl>(app: &App<Ms, Mdl>, routes: fn(&Url) -> Ms)
116-
where
117-
Ms: Clone,
118-
{
119-
// We can't reuse the app later to store the popstate once moved into the closure.
120-
let app_for_closure = app.clone();
121-
let closure = Closure::wrap(Box::new(move |ev: web_sys::Event| {
122-
let ev = ev
123-
.dyn_ref::<web_sys::PopStateEvent>()
124-
.expect("Problem casting as Popstate event");
125-
126-
let url: Url = match ev.state().as_string() {
127-
Some(state_str) => serde_json::from_str(&state_str)
128-
.expect("Problem deserialzing popstate state"),
129-
// This might happen if we go back to a page before we started routing. (?)
130-
None => {
131-
let empty: Vec<String> = Vec::new();
132-
Url::new(empty)
133-
}
134-
};
135-
>>>>>>> e449e6645f76720a29d6dfa7971198381acc247c
136114

137115
fn clean_url(mut url: Url) -> Url {
138116
let mut cleaned_path = vec![];
@@ -174,8 +152,6 @@ pub fn push_route(mut url: Url) {
174152
// the existing path. Not doing so will add the path to the existing one.
175153
let path = String::from("/") + &url.path.join("/");
176154

177-
crate::log(&path);
178-
179155
util::window()
180156
.history()
181157
.expect("Can't find history")
@@ -253,10 +229,12 @@ pub fn setup_link_listener<Ms: Clone, Mdl>(app: &App<Ms, Mdl>, routes: fn(&Url)
253229
}
254230
if let Some(href) = el.get_attribute("href") {
255231
if let Some(first) = href.chars().next() {
232+
// The first character being / indicates a rel link, which is what
233+
// we're intercepting.
256234
if first == '/' {
257235
event.prevent_default();
258-
// Route internally based on href
259-
let url = Url::new(vec![href]);
236+
// Route internally based on href's value
237+
let url = Url::new(href.split('/').collect());
260238
app_for_closure.update(routes(&url));
261239
push_route(url);
262240
}

0 commit comments

Comments
 (0)