feat(router): mount Landing at / with auth-aware redirect
- / (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 <a href>, causing SPA reload) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
6
frontend/src/router/meta.d.ts
vendored
6
frontend/src/router/meta.d.ts
vendored
@@ -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
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
<!-- NAV -->
|
||||
<nav class="nav">
|
||||
<div class="container nav-inner">
|
||||
<a href="/" class="brand">
|
||||
<router-link to="/" class="brand">
|
||||
<span class="hex">⬢</span>
|
||||
<span>PURO AI</span>
|
||||
</a>
|
||||
</router-link>
|
||||
<div class="nav-links">
|
||||
<a href="#features">产品</a>
|
||||
<a href="/docs">文档</a>
|
||||
|
||||
Reference in New Issue
Block a user