This repository has been archived by the owner on Sep 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
197 lines (170 loc) · 4.86 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MicroSPA</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
<script type="module">
import microspa from './index.js'
/*
Here we are defining the root of the router:
<main id="app">
And we set 4 custom elements:
<ms-ticker>: vanilla JS,
<ms-counter>: Superfine,
<ms-todo>: Hyperapp,
<ms-error>: throw error or reject promise
*/
window.stop = microspa(document.getElementById('app'), {
ticker: './components/ticker.js',
counter: './components/counter.js',
todo: './components/todo.js',
error: './components/error.js'
})
</script>
</head>
<body>
<nav>
<!--
This navigate to:
<main id="app">
-->
<a href="#/">Home</a> |
<!--
This navigate to:
<template data-path="#/todo">
The value will be:
plant a tree
-->
<a href="#/todo?value=plant%20a%20tree">Todo</a> |
<!--
This navigate to:
<template data-path="#/tickers">
-->
<a href="#/tickers">2 tickers</a> |
<!--
This navigate to:
<template data-path="#/counter/:start">
-->
<a href="#/counter/7?start=9&x=11">3 Counters</a> |
<!--
This navigate to:
<template data-path="#/error">
-->
<a href="#/error">Error example</a> |
<!--
This navigate to:
<template data-default>
-->
<a href="#/this/is/404">Not Founded</a> |
<!--This completely stops the router -->
<a href="javascript:;" onclick="stop()">Stop Router</a> |
<!--This goes to test page -->
<a href="tests">Tests</a> |
<!--This goes to github -->
<a href="https://github.com/marcodpt/microspa">GitHub</a>
</nav>
<!--
This is the root of the router,
by default #/ but you can add a
data-path attibute.
The `ms-todo` will start with:
read a book
-->
<main id="app">
<h1>MicroSPA</h1>
<p>Hello world! From MicroSPA</p>
<ms-todo value="read a book"></ms-todo>
</main>
<!-- This is a single component route -->
<template data-path="#/todo">
<ms-todo></ms-todo>
</template>
<template data-path="#/tickers">
<h1> 2 tickers</h1>
<!--
This ticker will start with
query param `start` or default 0
-->
<ms-ticker></ms-ticker>
<!--This ticker will start always with 10-->
<ms-ticker start="10"></ms-ticker>
</template>
<!--
The nav link will set the hash to:
#/counter/7?start=9&x=11
-->
<template data-path="#/counter/:start">
<!--
starts with 7,
path has higher priority than query.
-->
<ms-counter></ms-counter>
<!--
starts with 1,
attributes has the highest priority.
-->
<ms-counter start="1"></ms-counter>
<!--
start with 11,
data-start="x" sets the `start` to `x`.
-->
<ms-counter data-start="x"></ms-counter>
</template>
<template data-path="#/error">
<!--
Display <h1>Custom loading...</h1> for 2s,
then reject with <template data-error>
-->
<ms-error message="first error" delay="2">
<h1>Custom loading...</h1>
</ms-error>
<!--
Display <template data-loading> for 1s,
then reject with <template data-error>
-->
<ms-error message="second error" delay="1"></ms-error>
<!--
Throws an error and
display <template data-error>
-->
<ms-error message="third error"></ms-error>
<!--
Throws an error and
display <h1>Custom error</h1>
-->
<ms-error
message="fourth error"
error="<h1>Custom error</h1>"
></ms-error>
</template>
<!--
This route will be displayed every time
the router does not match any route
-->
<template data-default>
<h1>Not Found!</h1>
<p>Sorry, page not found. <a href="#/">Go home</a></p>
</template>
<!--
This template will be displayed inside a custom element,
if it reject the promise or throw an error
and has no error attribute
-->
<template data-error>
<h1>Error!</h1>
<p>Error executing script!</p>
<p>Please check browser logs!</p>
</template>
<!--
This template will be displayed inside a custom element,
if it is loading and it has no innerHTML.
-->
<template data-loading>
<h1>Loading...</h1>
</template>
</body>
</html>