Skip to content

Commit ac3c08d

Browse files
committed
finished the router
1 parent e6c2716 commit ac3c08d

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

docs/js/OpenScript.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ var OpenScript = {
88
* OpenScript's Router Class
99
*/
1010
Router: class {
11-
/**
12-
* URL
13-
* @type {URL}
14-
*/
15-
url;
1611

1712
/**
1813
* Current Prefix
@@ -44,12 +39,9 @@ var OpenScript = {
4439
reset;
4540

4641
/**
47-
*
48-
* @param {string} url
42+
*
4943
*/
50-
constructor(url = null) {
51-
url = url ?? window.location.href;
52-
this.url = new URL(url);
44+
constructor() {
5345

5446
this.reset = OpenScript.State.state(false);
5547

@@ -75,7 +67,7 @@ var OpenScript = {
7567

7668
if(cmp.length < 1) continue;
7769

78-
key = /^\{w+\}$/.test(cmp) ? '*' : cmp;
70+
key = /^\{\w+\}$/.test(cmp) ? '*' : cmp;
7971

8072
let val = map.get(key);
8173
if(!val) val = [cmp, new Map()];
@@ -104,8 +96,10 @@ var OpenScript = {
10496
* Executes the actions based on the url
10597
*/
10698
listen(){
107-
108-
let paths = this.url.pathname.split('/');
99+
let url = new URL(window.location.href);
100+
this.params = {};
101+
102+
let paths = url.pathname.split('/');
109103

110104
let map = this.map;
111105

@@ -125,7 +119,7 @@ var OpenScript = {
125119
map = next[1];
126120
}
127121

128-
this.qs = new URLSearchParams(this.url.search);
122+
this.qs = new URLSearchParams(url.search);
129123

130124
map.get('->')[1]();
131125

docs/js/app.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ ojs(async e => {
2222
parent: rc.root,
2323
resetParent: route.reset
2424
});
25+
26+
console.log('executed 1');
2527
})
2628

27-
.on('docs.html', () => {
29+
.on('docs.html/{id}/here', () => {
2830
req('Docs');
2931

3032
h.Docs({
@@ -33,7 +35,29 @@ ojs(async e => {
3335
});
3436

3537
console.log('executed 2');
36-
});
38+
})
39+
.on('docs.html/{id}/blue', () => {
40+
req('Docs');
41+
42+
h.Docs({
43+
parent: rc.root,
44+
resetParent: route.reset
45+
});
46+
47+
console.log('executed 2');
48+
})
49+
50+
.on('docs.html/hello/here', () => {
51+
req('Docs');
52+
53+
h.Docs({
54+
parent: rc.root,
55+
resetParent: route.reset
56+
});
57+
58+
console.log('executed 2');
59+
})
60+
;
3761
});
3862

3963
route.listen();

0 commit comments

Comments
 (0)