-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.es2015.js
56 lines (43 loc) · 1.4 KB
/
router.es2015.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const Router = (el, attr, wrapper, push = false) => {
if ($.isArray(el) && $.isArray(attr)) {
$.each(el, (index, value) => {
$(value).click((e) => {
let target = $(e.target).attr(attr[index])
$.ajax({
type: 'GET',
url: target,
success: (data) => {
$(wrapper).html(data)
let stateObj = {}
if (push) history.pushState(stateObj, null, target)
}
})
return false
})
})
}
else {
$(el).click((e) => {
let target = $(e.target).attr(attr)
$.ajax({
type: 'GET',
url: target,
success: (data) => {
$(wrapper).html(data)
let stateObj = {}
if (push) history.pushState(stateObj, null, target)
}
})
return false
})
}
window.onpopstate = (event) => {
$.ajax({
type: 'GET',
url: document.location,
success: (data) => {
$(wrapper).html(data)
}
})
}
}