|
@@ -35,21 +35,24 @@ func (r *Router) HandleFunc(path string, handler HandlerFunc) *Route {
|
35
|
35
|
}
|
36
|
36
|
|
37
|
37
|
func (r *Router) Listen() {
|
38
|
|
- r.RegisterLinks()
|
|
38
|
+ r.RegisterLinks("body a")
|
39
|
39
|
}
|
40
|
40
|
|
41
|
|
-func (r *Router) RegisterLinks() {
|
|
41
|
+func (r *Router) RegisterLinks(querySelector string) {
|
42
|
42
|
document := dom.GetWindow().Document().(dom.HTMLDocument)
|
43
|
|
- for _, link := range document.Links() {
|
|
43
|
+ links := document.QuerySelectorAll(querySelector)
|
|
44
|
+
|
|
45
|
+ for _, link := range links {
|
44
|
46
|
href := link.GetAttribute("href")
|
45
|
47
|
switch {
|
46
|
48
|
|
47
|
49
|
case strings.HasPrefix(href, "/") && !strings.HasPrefix(href, "//"):
|
48
|
50
|
|
49
|
51
|
if r.listener != nil {
|
50
|
|
- link.RemoveEventListener("click", true, r.listener)
|
|
52
|
+ link.RemoveEventListener("click", false, r.listener)
|
51
|
53
|
}
|
52
|
|
- r.listener = link.AddEventListener("click", true, r.linkHandler)
|
|
54
|
+
|
|
55
|
+ r.listener = link.AddEventListener("click", false, r.linkHandler)
|
53
|
56
|
}
|
54
|
57
|
}
|
55
|
58
|
}
|
|
@@ -83,7 +86,7 @@ func (r *Router) linkHandler(event dom.Event) {
|
83
|
86
|
routeVars := make(map[string]string)
|
84
|
87
|
|
85
|
88
|
for i, part := range parts {
|
86
|
|
- routeVars[matchedRoute.varNames[i]] = part
|
|
89
|
+ routeVars[matchedRoute.varNames[i]+`}`] = part
|
87
|
90
|
}
|
88
|
91
|
|
89
|
92
|
var ctx context.Context
|