2022-06-20 10:38:49 +02:00
|
|
|
<template>
|
2022-06-30 03:53:40 +02:00
|
|
|
<KeepAlive :max="defaultStore.state.numberOfPageCache">
|
2022-07-19 14:36:33 +02:00
|
|
|
<Suspense>
|
|
|
|
<component :is="currentPageComponent" :key="key" v-bind="Object.fromEntries(currentPageProps)"/>
|
|
|
|
|
|
|
|
<template #fallback>
|
|
|
|
Loading...
|
|
|
|
</template>
|
|
|
|
</Suspense>
|
2022-06-20 10:38:49 +02:00
|
|
|
</KeepAlive>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { inject, nextTick, onMounted, onUnmounted, watch } from 'vue';
|
|
|
|
import { Router } from '@/nirax';
|
2022-06-30 03:53:40 +02:00
|
|
|
import { defaultStore } from '@/store';
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
router?: Router;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const router = props.router ?? inject('router');
|
|
|
|
|
|
|
|
if (router == null) {
|
|
|
|
throw new Error('no router provided');
|
|
|
|
}
|
|
|
|
|
2022-06-29 09:06:13 +02:00
|
|
|
let currentPageComponent = $shallowRef(router.getCurrentComponent());
|
2022-06-20 10:38:49 +02:00
|
|
|
let currentPageProps = $ref(router.getCurrentProps());
|
|
|
|
let key = $ref(router.getCurrentKey());
|
|
|
|
|
|
|
|
function onChange({ route, props: newProps, key: newKey }) {
|
|
|
|
currentPageComponent = route.component;
|
|
|
|
currentPageProps = newProps;
|
|
|
|
key = newKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
router.addListener('change', onChange);
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
router.removeListener('change', onChange);
|
|
|
|
});
|
|
|
|
</script>
|