From 9ec020015dcbc01b43154022be856c3a847a7ada Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 28 Jun 2022 17:59:23 +0900 Subject: [PATCH] chore(client): fix #8858 --- packages/client/src/nirax.ts | 5 +++++ packages/client/src/ui/deck.vue | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/packages/client/src/nirax.ts b/packages/client/src/nirax.ts index cae4edaf1..6db633566 100644 --- a/packages/client/src/nirax.ts +++ b/packages/client/src/nirax.ts @@ -66,6 +66,7 @@ export class Router extends EventEmitter<{ private currentKey = Date.now().toString(); public currentRoute: ShallowRef = shallowRef(null); + public navHook: ((path: string) => boolean) | null = null; constructor(routes: Router['routes'], currentPath: Router['currentPath']) { super(); @@ -192,6 +193,10 @@ export class Router extends EventEmitter<{ } public push(path: string) { + if (this.navHook) { + const cancel = this.navHook(path); + if (cancel) return; + } const beforePath = this.currentPath; this.navigate(path, null); this.emit('push', { diff --git a/packages/client/src/ui/deck.vue b/packages/client/src/ui/deck.vue index 743326479..b3b9ddd55 100644 --- a/packages/client/src/ui/deck.vue +++ b/packages/client/src/ui/deck.vue @@ -65,6 +65,13 @@ import { $i } from '@/account'; import { i18n } from '@/i18n'; import { mainRouter } from '@/router'; +if (deckStore.state.navWindow) { + mainRouter.navHook = (path) => { + os.pageWindow(path); + return true; + }; +} + const isMobile = ref(window.innerWidth <= 500); window.addEventListener('resize', () => { isMobile.value = window.innerWidth <= 500;