Skip to content

Commit 4ffc820

Browse files
authored
登录后从入口页跳转到首页
修复入口页登录后跳转并稳定路由视图;启用 PWA 自动更新与放宽 CSP
2 parents 9ea27f0 + a607b8b commit 4ffc820

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

src/App.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ const handleDiscard = async () => {
153153
154154
<Suspense v-if="layoutMode === 'modern'">
155155
<template #default>
156-
<router-view v-slot="{ Component }">
156+
<router-view v-slot="{ Component, route: viewRoute }">
157157
<transition name="fade" mode="out-in">
158-
<component :is="Component" />
158+
<component v-if="Component" :is="Component" :key="viewRoute.fullPath" />
159159
</transition>
160160
</router-view>
161161
</template>
@@ -173,9 +173,9 @@ const handleDiscard = async () => {
173173
<template v-else-if="isPublicRoute">
174174
<Suspense>
175175
<template #default>
176-
<router-view v-slot="{ Component }">
176+
<router-view v-slot="{ Component, route: viewRoute }">
177177
<transition name="fade" mode="out-in">
178-
<component :is="Component" />
178+
<component v-if="Component" :is="Component" :key="viewRoute.fullPath" />
179179
</transition>
180180
</router-view>
181181
</template>

src/stores/session.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ export const useSessionStore = defineStore('session', () => {
1111
const initialData = ref(null);
1212
const publicConfig = ref({ enablePublicPage: true }); // Default true until fetched
1313
const isConfigReady = ref(false);
14-
const loginReloadKey = 'misub:post-login-reload';
15-
16-
const canUseSessionStorage = () => {
17-
try {
18-
return typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined';
19-
} catch (error) {
20-
return false;
21-
}
22-
};
23-
2414
async function checkSession() {
2515
try {
2616
// Parallel fetch of initial data (auth check) and public config

src/views/Entrance.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<script setup>
99
import { computed, defineAsyncComponent, ref, watch } from 'vue';
10-
import { useRoute } from 'vue-router';
10+
import { useRoute, useRouter } from 'vue-router';
1111
import { storeToRefs } from 'pinia';
1212
import { useSessionStore } from '../stores/session';
1313
import LoadingSpinner from '../components/ui/LoadingSpinner.vue';
@@ -17,6 +17,7 @@ const Login = defineAsyncComponent(() => import('../components/modals/Login.vue'
1717
const NotFound = defineAsyncComponent(() => import('./NotFound.vue'));
1818
1919
const route = useRoute();
20+
const router = useRouter();
2021
const sessionStore = useSessionStore();
2122
const { publicConfig, isConfigReady, sessionState } = storeToRefs(sessionStore);
2223
@@ -30,7 +31,16 @@ watch([() => route.path, publicConfig, isConfigReady], () => {
3031
}
3132
}, { immediate: true });
3233
34+
watch(sessionState, (state) => {
35+
if (state === 'loggedIn' && route.path !== '/') {
36+
router.replace('/');
37+
}
38+
}, { immediate: true });
39+
3340
async function checkPath() {
41+
if (sessionState.value === 'loggedIn') {
42+
return;
43+
}
3444
// 1. Get Configured Path
3545
// Settings might be in initialData (if logged in) or publicConfig (if not)
3646
// Actually, 'customLoginPath' might be considered a 'secret' setting?

vite.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ export default defineConfig({
99
vue(),
1010
tailwindcss(),
1111
VitePWA({
12-
registerType: 'prompt',
12+
registerType: 'autoUpdate',
1313
workbox: {
14+
skipWaiting: true,
15+
clientsClaim: true,
1416
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'],
1517
cleanupOutdatedCaches: true,
1618
// 使用离线回退页面,并显式忽略订阅路径

0 commit comments

Comments
 (0)