-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
34 lines (32 loc) · 1008 Bytes
/
Copy pathindex.html
File metadata and controls
34 lines (32 loc) · 1008 Bytes
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>example</title>
</head>
<body>
<a href="/post">/post</a> <br>
<a href="/post/123">/post/123</a>
<p id="content"></p>
<script src="/src/SRouter.js"></script>
<script>
var as = document.getElementsByTagName('a');
var content = document.getElementById('content');
Array.prototype.forEach.call(as, function (item) {
item.addEventListener('click', function (event) {
event.preventDefault();
SRouter.go(item.getAttribute('href'));
})
});
SRouter.config({
mode: 'history'
}).add('/post','post', function () {
content.innerHTML = 'post'
}).add('/post/:postid', function (router) {
content.innerHTML = JSON.stringify(router);
}).default(function () {
content.innerHTML = '都不匹配';
}).listen();
</script>
</body>
</html>