diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-03-19 18:06:22 +0900 |
|---|---|---|
| committer | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-03-19 18:06:22 +0900 |
| commit | 81ac71f7e59623625369aaff75a8712923450b80 (patch) | |
| tree | c36eb84c0724121db8d2381cbb8fab0593ff53ea /packages/frontend/src/components/global/NestedRouterView.vue | |
| parent | better import paths (diff) | |
| download | sharkey-81ac71f7e59623625369aaff75a8712923450b80.tar.gz sharkey-81ac71f7e59623625369aaff75a8712923450b80.tar.bz2 sharkey-81ac71f7e59623625369aaff75a8712923450b80.zip | |
refactor(frontend): router refactoring
Diffstat (limited to 'packages/frontend/src/components/global/NestedRouterView.vue')
| -rw-r--r-- | packages/frontend/src/components/global/NestedRouterView.vue | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/packages/frontend/src/components/global/NestedRouterView.vue b/packages/frontend/src/components/global/NestedRouterView.vue index 5b22d0b7a8..af00347db8 100644 --- a/packages/frontend/src/components/global/NestedRouterView.vue +++ b/packages/frontend/src/components/global/NestedRouterView.vue @@ -14,8 +14,9 @@ SPDX-License-Identifier: AGPL-3.0-only </template> <script lang="ts" setup> -import { inject, onBeforeUnmount, provide, ref, shallowRef } from 'vue'; -import type { Router, Resolved } from '@/router.js'; +import { inject, provide, ref, shallowRef } from 'vue'; +import type { Router } from '@/router.js'; +import type { PathResolvedResult } from '@/lib/nirax.js'; import MkLoadingPage from '@/pages/_loading_.vue'; import { DI } from '@/di.js'; @@ -32,7 +33,7 @@ if (router == null) { const currentDepth = inject(DI.routerCurrentDepth, 0); provide(DI.routerCurrentDepth, currentDepth + 1); -function resolveNested(current: Resolved, d = 0): Resolved | null { +function resolveNested(current: PathResolvedResult, d = 0): PathResolvedResult | null { if (d === currentDepth) { return current; } else { @@ -47,19 +48,13 @@ function resolveNested(current: Resolved, d = 0): Resolved | null { const current = resolveNested(router.current)!; const currentPageComponent = shallowRef('component' in current.route ? current.route.component : MkLoadingPage); const currentPageProps = ref(current.props); -const key = ref(router.getCurrentPath()); +const key = ref(router.getCurrentFullPath()); -function onChange({ resolved }) { +router.useListener('change', ({ resolved }) => { const current = resolveNested(resolved); if (current == null || 'redirect' in current.route) return; currentPageComponent.value = current.route.component; currentPageProps.value = current.props; - key.value = router.getCurrentPath(); -} - -router.addListener('change', onChange); - -onBeforeUnmount(() => { - router.removeListener('change', onChange); + key.value = router.getCurrentFullPath(); }); </script> |