Skip to content

Commit

Permalink
🎨 Use navigateTo
Browse files Browse the repository at this point in the history
  • Loading branch information
Aira-Sakuranomiya committed Nov 1, 2023
1 parent 1dc399c commit 86ac338
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
2 changes: 1 addition & 1 deletion layouts/settings.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
const currentSetting = computed({
get: () => currentSettingsPage(),
set: async id => { await forceNavigate(`/settings/${id}`, () => currentSetting.value === id); },
set: async id => { await navigateTo(`/settings/${id}`); },
});
const search = ref("");
const main = ref<HTMLElement>();
Expand Down
2 changes: 1 addition & 1 deletion layouts/user-page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
});
const currentTab = computed({
get: () => currentUserTab(),
set: async id => { await forceNavigate(`/user/${uid}/${id}`, () => currentTab.value === id); },
set: async id => { await navigateTo(`/user/${uid}/${id}`); },
});
useHead({ title: user.value?.username ? t.user_page.title_affix(user.value.username) : undefined });
Expand Down
12 changes: 0 additions & 12 deletions utils/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ export function navigate(path: string) {
useRouter().push(useLocalePath()(path));
}

/**
* 强制导航到页面,如果没有导航到该页面,则再次发起请求,直到导航到该页面为止。
* @param path - 路由地址。
* @param until - 确认已导航到该页面?
*/
export async function forceNavigate(path: string, until: () => boolean) {
while (!until()) {
navigate(path);
await delay(50); // 解决有可能会跳转失败的问题。
}
}

/**
* 切换语言。
* @param lang - 语言代码。
Expand Down

0 comments on commit 86ac338

Please sign in to comment.