mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-03 21:56:18 +02:00
refactor(frontend): router refactoring
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user