fix: Keep home timelines laoded

This commit is contained in:
freeplay 2023-07-15 16:34:30 -04:00
parent 63b3666b71
commit 9990cc9a44
3 changed files with 21 additions and 1 deletions

View file

@ -1,6 +1,22 @@
<template>
<KeepAlive>
<Suspense v-if="currentPageKeepAlive">
<component
:is="currentPageComponent"
:key="key"
v-bind="Object.fromEntries(currentPageProps)"
tabindex="-1"
v-focus
style="outline: none"
/>
<template #fallback>
<MkLoading />
</template>
</Suspense>
</KeepAlive>
<KeepAlive :max="defaultStore.state.numberOfPageCache">
<Suspense>
<Suspense v-if="!currentPageKeepAlive">
<component
:is="currentPageComponent"
:key="key"
@ -57,6 +73,7 @@ function resolveNested(current: Resolved, d = 0): Resolved | null {
const current = resolveNested(router.current)!;
let currentPageComponent = $shallowRef(current.route.component);
let currentPageKeepAlive = $shallowRef(current.route.keepAlive);
let currentPageProps = $ref(current.props);
let key = $ref(
current.route.path + JSON.stringify(Object.fromEntries(current.props)),
@ -66,6 +83,7 @@ function onChange({ resolved, key: newKey }) {
const current = resolveNested(resolved);
if (current == null) return;
currentPageComponent = current.route.component;
currentPageKeepAlive = current.route.keepAlive;
currentPageProps = current.props;
key =
current.route.path + JSON.stringify(Object.fromEntries(current.props));

View file

@ -12,6 +12,7 @@ type RouteDef = {
loginRequired?: boolean;
name?: string;
hash?: string;
keepAlive?: boolean;
globalCacheKey?: string;
children?: RouteDef[];
};

View file

@ -657,6 +657,7 @@ export const routes = [
component: $i
? page(() => import("./pages/timeline.vue"))
: page(() => import("./pages/welcome.vue")),
keepAlive: true,
globalCacheKey: "index",
},
{