mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-17 06:59:01 +01:00
406b4bdbe7
* refactor(frontend): 非推奨となったReactivity Transformを使わないように * refactor: 不要な括弧を除去 * fix: 不要なアノテーションを除去 * fix: Refの配列をrefしている部分の対応 * refactor: 不要な括弧を除去 * fix: lint * refactor: Ref、ShallowRef、ComputedRefの変数の宣言をletからconstに置換 * fix: type error * chore: drop reactivity transform from eslint configuration * refactor: remove unnecessary import * fix: 対応漏れ
66 lines
1.7 KiB
Vue
66 lines
1.7 KiB
Vue
<!--
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
-->
|
|
|
|
<template>
|
|
<KeepAlive :max="defaultStore.state.numberOfPageCache">
|
|
<Suspense :timeout="0">
|
|
<component :is="currentPageComponent" :key="key" v-bind="Object.fromEntries(currentPageProps)"/>
|
|
|
|
<template #fallback>
|
|
<MkLoading/>
|
|
</template>
|
|
</Suspense>
|
|
</KeepAlive>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { inject, onBeforeUnmount, provide, shallowRef, ref } from 'vue';
|
|
import { Resolved, Router } from '@/nirax';
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
const props = defineProps<{
|
|
router?: Router;
|
|
}>();
|
|
|
|
const router = props.router ?? inject('router');
|
|
|
|
if (router == null) {
|
|
throw new Error('no router provided');
|
|
}
|
|
|
|
const currentDepth = inject('routerCurrentDepth', 0);
|
|
provide('routerCurrentDepth', currentDepth + 1);
|
|
|
|
function resolveNested(current: Resolved, d = 0): Resolved | null {
|
|
if (d === currentDepth) {
|
|
return current;
|
|
} else {
|
|
if (current.child) {
|
|
return resolveNested(current.child, d + 1);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
const current = resolveNested(router.current)!;
|
|
const currentPageComponent = shallowRef(current.route.component);
|
|
const currentPageProps = ref(current.props);
|
|
const key = ref(current.route.path + JSON.stringify(Object.fromEntries(current.props)));
|
|
|
|
function onChange({ resolved, key: newKey }) {
|
|
const current = resolveNested(resolved);
|
|
if (current == null) return;
|
|
currentPageComponent.value = current.route.component;
|
|
currentPageProps.value = current.props;
|
|
key.value = current.route.path + JSON.stringify(Object.fromEntries(current.props));
|
|
}
|
|
|
|
router.addListener('change', onChange);
|
|
|
|
onBeforeUnmount(() => {
|
|
router.removeListener('change', onChange);
|
|
});
|
|
</script>
|