Commit 6c72db9f authored by xiaoye's avatar xiaoye

更好的匹配url方法

parent 02e6308a
...@@ -275,7 +275,7 @@ ...@@ -275,7 +275,7 @@
await (new Promise(resolve => setTimeout(resolve, 500))); await (new Promise(resolve => setTimeout(resolve, 500)));
page.tournament = true; page.tournament = true;
const url = window.location.href.split('/?'); const url = window.location.href.split('/?');
window.location.replace(`${url[0]}/tournament/${search.result.tournaments[v].id}/?${url[1] ?? ''}`) window.location.replace(`${url[0].replace(/\/?$/, '')}/tournament/${search.result.tournaments[v].id}${url[1] ? `/?${url[1]}` : ''}`);
}, },
menu : async(): Promise<void> => { menu : async(): Promise<void> => {
page.tournament = false; page.tournament = false;
...@@ -535,12 +535,15 @@ ...@@ -535,12 +535,15 @@
// @ts-ignore // @ts-ignore
emitter.on(tournamentReload, tournament.init); emitter.on(tournamentReload, tournament.init);
const url = window.location.href.match(/tournament\/(\d+)[^\/]*\/\?/); const url = window.location.pathname.match(/\/tournament\/([^\/]+)(?=\/|$)/);
if (url && !isNaN(parseInt(url[1]))) { if (url && !isNaN(parseInt(url[1]))) {
page.menu = false; page.menu = false;
page.tournament = true; page.tournament = true;
} else { } else {
search.on(); if (window.location.pathname.length > 1)
window.location.replace(window.location.href.replace(window.location.pathname, ''))
else
search.on();
} }
}); });
......
...@@ -329,12 +329,9 @@ ...@@ -329,12 +329,9 @@
height : 0, height : 0,
loading : false, loading : false,
clear : async () : Promise<void>=> { clear : async () : Promise<void>=> {
const url = window.location.href.match(/(\/tournament\/[^\/]+)(?=\/\?)/); tournament.this = undefined;
if (url) { await (new Promise(resolve => setTimeout(resolve, 450)));
tournament.this = undefined; window.location.replace(window.location.href.replace(window.location.pathname, ''))
await (new Promise(resolve => setTimeout(resolve, 450)));
window.location.replace(window.location.href.replace(url[1], ''));
}
}, },
get : async (id : number) : Promise<void> => { get : async (id : number) : Promise<void> => {
const t = await Tabulator.Tournament.Find(Mycard.token, id); const t = await Tabulator.Tournament.Find(Mycard.token, id);
...@@ -377,7 +374,7 @@ ...@@ -377,7 +374,7 @@
}); });
onBeforeMount(() => { onBeforeMount(() => {
const url = window.location.href.match(/tournament\/(\d+)[^\/]*\/\?/); const url = window.location.pathname.match(/\/tournament\/([^\/]+)(?=\/|$)/);
url && !isNaN(parseInt(url[1])) ? page.get(parseInt(url[1])) : page.clear(); url && !isNaN(parseInt(url[1])) ? page.get(parseInt(url[1])) : page.clear();
// @ts-ignore // @ts-ignore
emitter.on(updateTournament, participant.update); emitter.on(updateTournament, participant.update);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment