-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
87 lines (79 loc) · 2.45 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
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8" />
<title>Router ES6</title>
<style>
a {
text-decoration: none;
border-radius: 10px;
padding: 20px 40px;
background: yellow;
color: black;
font-size: 17px;
text-transform: capitalize;
margin: 20px;
}
</style>
</head>
<body>
<script type="module">
"use strict";
import RouterProvide from "./src/Router.js?version=2300";
(async window => {
const Router = RouterProvide.create();
const templateLinks = `
<br><br><a href="${Router.toRoute("/")}">Go to Init</a>
<br><br><br><br><a href="${Router.toRoute(
"/home"
)}">Go to Home</a>
<br><br><br><br><a href="${Router.toRoute(
"/toRedirect"
)}">Go Redirect</a>
<br><br><br><br><a href="${Router.toRoute(
"/perfil/Machine/10"
)}">Go to profile Router</a>
<br><br><br>
`;
Router.any("/", async (data, viewRouter) => {
console.log("Init !!");
viewRouter.innerHTML = templateLinks;
});
Router.any(
"/home",
async (data, viewRouter, next) => {
data.id = Math.random() * 1000;
next();
},
async ({ view, id }, viewRouter, next) => {
const homePromise = () =>
new Promise((resolve, reject) => {
resolve("Home !! id is: " + id);
});
viewRouter.innerHTML = templateLinks + (await homePromise());
next();
},
() => console.log("Finish exec middleware")
);
Router.any("/toRedirect", () => {
Router.redirect("/redirected");
});
Router.any("/redirected", (data, viewRouter) => {
viewRouter.innerHTML =
templateLinks +
`
<h1>Redirecionado com sucesso!!</h1>
`;
});
Router.any("/perfil/{name}/{id}", async ({ name, id }, viewRouter) => {
viewRouter.innerHTML =
templateLinks +
`
<h1>Perfil ${name} is ID ${id}</h1>
`;
});
Router.dispatch();
})(window);
</script>
</body>
</html>