Skip to content

Commit 105337f

Browse files
committed
fixed router bug
1 parent 791a98f commit 105337f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

OpenScript.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,19 @@ var OpenScript = {
185185
*/
186186
to(path, qs = {}){
187187

188-
if(path[0] != '/') path = '/' + path;
188+
path = `${this.path}/${path}`.trim();
189+
190+
let paths = path.split('/');
191+
192+
path = '';
193+
194+
for(let p of paths) {
195+
if(p.length === 0 || /^\s+$/.test(p)) continue;
196+
197+
if(path.length) path += '/';
198+
199+
path += p.trim();
200+
}
189201

190202
let s = '';
191203

@@ -196,7 +208,7 @@ var OpenScript = {
196208

197209
if(s.length > 0) s = `?${s}`;
198210

199-
this.history().pushState({random: Math.random()}, '', `${path}${s}`);
211+
this.history().pushState({random: Math.random()}, '', `/${path}${s}`);
200212
this.reset.value = true;
201213

202214
return this.listen();

0 commit comments

Comments
 (0)