-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (108 loc) · 3.97 KB
/
index.html
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
<base href="/">
<title>wc-router</title>
<script src="bower_components/webcomponentsjs/webcomponents-loader.js"></script>
<style>
button {
display: block;
padding: 8px;
margin: 0;
margin-bottom: 8px;
}
a {
display: block;
color: #000;
}
a:hover {
color: red;
}
.route-container {
display: flex;
justify-content: space-between;
}
.route-text {
flex-grow: 1;
flex-shrink: 0;
flex-basis: 50%;
}
</style>
</head>
<body>
<wc-router id="route2">
<wc-path name="shoes" pattern="^/shoes$"></wc-path>
<wc-path name="jackets" pattern="^/jackets$"></wc-path>
</wc-router>
<wc-router main id="route1">
<wc-path name="home" pattern="^/$"></wc-path>
<wc-path name="about" pattern="^/about$"></wc-path>
<wc-path name="category" pattern="^/category$"></wc-path>
<wc-path name="404" pattern="^/.*$"></wc-path>
</wc-router>
<h1>Demo & Debug</h1>
<div class="route-container">
<div class="route-text">
<h2>Route 1</h2>
<div id="route1Detail"></div>
</div>
<div class="route-text">
<h2>Route 2</h2>
<div id="route2Detail"></div>
</div>
</div>
<div>
<h3>Links</h3>
<a href="/">/home</a>
<a href="/about">/about</a>
<a href="/category/shoes">/category/shoes</a>
<a href="/category/shoes#nike">/category/shoes#nike</a>
<a href="/category/shoes?name=nike">/category/shoes?name=nike</a>
<a href="/category/shoes?name=adidas">/category/shoes?name=adidas</a>
<a href="/category/jackets">/category/jackets</a>
<a href="/about" target="_blank">/about _blank</a>
<a href="tel:070123456">tel:070123456</a>
<a href="mailto:[email protected]">mailto:[email protected]</a>
<h3>Router push() & replace()</h3>
<button id="button1">/category/shoes</button>
<button id="button2">/category/sweaters</button>
</div>
<script>
window.addEventListener('WebComponentsReady', event => {
console.log(`webcomponentsready`);
});
window.addEventListener('HTMLImportsLoaded', event => {
console.log(`HTMLImportsLoaded`);
});
document.getElementById("route1").addEventListener('route-change', event => {
// console.log('Route one');
// console.log(event.detail);
// console.log('----------------');
document.getElementById("route2").route = event.detail.subroute;
route1Detail.innerHTML = _detailText(event.detail);;
});
document.getElementById("route2").addEventListener('route-change', event => {
// console.log('Route two');
// console.log(event.detail);
// console.log('----------------');
route2Detail.innerHTML = _detailText(event.detail);
});
button1.addEventListener('click', event => route1.push('/category/shoes'));
button2.addEventListener('click', event => route1.replace('/category/sweaters'));
function _detailText(detail) {
return text = `
<b>currentPathname:</b> ${detail.currentPathname}<br>
<b>parentPathname:</b> ${detail.parentPathname}<br>
<b>pathname:</b> ${detail.pathname}<br>
<b>hash:</b> ${detail.hash}<br>
<b>queryObject:</b> ${JSON.stringify(detail.queryObject)}<br>
<b>name:</b> ${detail.name}<br>
<b>active:</b> ${detail.active}<br>
`;
}
</script>
<link rel="import" href="wc-router.html">
</body>
</html>