-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (31 loc) · 1.04 KB
/
index.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
export default class IndexViewModel extends crsbinding.classes.ViewBase {
async connectedCallback() {
await super.connectedCallback();
crsbinding.data.updateUI(this, "routes");
}
async preLoad() {
await this._getRoutes();
}
async _getRoutes() {
return new Promise(resolve => {
const router = document.querySelector("crs-router");
const result = [];
const fn = () => {
router.removeEventListener("ready", fn);
const routes = router.routesDef;
for (let route of routes.routes) {
if (route.hash != "#404") {
result.push({title: route.title, hash: route.hash});
}
}
crsbinding.data.setProperty(this, "routes", result);
resolve();
};
if (router.routesDef != null) {
fn();
}
else {
router.addEventListener("ready", fn);}
})
}
}