From 284b5129acf96f1946971dcecd89dee04bce526d Mon Sep 17 00:00:00 2001 From: mini Date: Sun, 19 Apr 2026 21:14:12 +0800 Subject: [PATCH] feat(router): mount Landing at / with auth-aware redirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - / (anonymous) → LandingView - / (authenticated) → redirects to /dashboard via new meta.redirectIfAuth - Remove temporary /landing-preview route (Task 2 helper) - RouteMeta TS augmentation for redirectIfAuth - LandingView brand link uses router-link (was , causing SPA reload) Co-Authored-By: Claude Opus 4.7 (1M context) --- frontend/src/router/index.ts | 24 +++++++++++++--------- frontend/src/router/meta.d.ts | 6 ++++++ frontend/src/views/landing/LandingView.vue | 4 ++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 81065847..30062fe6 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -36,15 +36,6 @@ const routes: RouteRecordRaw[] = [ title: 'Home' } }, - { - path: '/landing-preview', - name: 'LandingPreview', - component: () => import('@/views/landing/LandingView.vue'), - meta: { - requiresAuth: false, - title: 'PURO AI' - } - }, { path: '/login', name: 'Login', @@ -133,7 +124,13 @@ const routes: RouteRecordRaw[] = [ // ==================== User Routes ==================== { path: '/', - redirect: '/home' + name: 'Landing', + component: () => import('@/views/landing/LandingView.vue'), + meta: { + requiresAuth: false, + title: 'PURO AI — 你的 AI 订阅,已经付过钱了', + redirectIfAuth: '/dashboard' + } }, { path: '/dashboard', @@ -542,6 +539,13 @@ router.beforeEach((to, _from, next) => { authInitialized = true } + // Auth-aware redirect for public pages that should bounce authenticated users elsewhere + // (e.g., Landing / at `/` redirects to /dashboard if user is logged in) + const redirectIfAuth = to.meta.redirectIfAuth + if (redirectIfAuth && authStore.isAuthenticated) { + return next(redirectIfAuth) + } + // Set page title const appStore = useAppStore() // For custom pages, use menu item label as document title diff --git a/frontend/src/router/meta.d.ts b/frontend/src/router/meta.d.ts index 7b2777c2..3f90eaa6 100644 --- a/frontend/src/router/meta.d.ts +++ b/frontend/src/router/meta.d.ts @@ -7,6 +7,12 @@ import 'vue-router' declare module 'vue-router' { interface RouteMeta { + /** + * If set, authenticated users visiting this route are redirected to this path. + * Used for public pages (e.g., Landing `/`) that should bounce logged-in users to the app. + */ + redirectIfAuth?: string + /** * Whether this route requires authentication * @default true diff --git a/frontend/src/views/landing/LandingView.vue b/frontend/src/views/landing/LandingView.vue index b7b758d7..93f3b577 100644 --- a/frontend/src/views/landing/LandingView.vue +++ b/frontend/src/views/landing/LandingView.vue @@ -6,10 +6,10 @@