import { createRouter, createWebHistory } from 'vue-router'; import MainLayout from '@/layouts/MainLayout.vue'; import Index from '@/views/public/Index.vue'; import Login from '@/views/public/Login.vue'; import SignUp from '@/views/public/SignUp.vue'; import Dashboard from '@/views/private/Dashboard.vue'; import AiInvestment from '@/views/private/AiInvestment.vue'; import StockMarket from '@/views/private/StockMarket.vue'; import EarningsPrediction from '@/views/private/EarningsPrediction.vue'; import TradingNews from '@/views/private/TradingNews.vue'; import History from '@/views/private/History.vue'; import NotFoundView from '@/views/NotFoundView.vue'; const routes = [ { path: '/', name: 'Index', component: Index, meta: { title: 'AriStockAI - 智能股票投资平台', requiresAuth: false } }, { path: '/app', name: 'App', component: MainLayout, meta: { requiresAuth: true }, children: [ { path: 'dashboard', name: 'Dashboard', component: Dashboard, meta: { title: '仪表盘' } }, { path: 'ai-investment', name: 'AiInvestment', component: AiInvestment, meta: { title: 'AI投资' } }, { path: 'stock-market', name: 'StockMarket', component: StockMarket, meta: { title: '股票市场' } }, { path: 'earnings-prediction', name: 'EarningsPrediction', component: EarningsPrediction, meta: { title: '收益预测' } }, { path: 'trading-news', name: 'TradingNews', component: TradingNews, meta: { title: '交易新闻' } }, { path: 'history', name: 'History', component: History, meta: { title: '历史记录' } } ] }, { path: '/login', name: 'Login', component: Login, meta: { title: '登录', requiresAuth: false }, beforeEnter: (to, from, next) => { if (localStorage.getItem('isLoggedIn') === 'true') { next('/app/dashboard'); } else { next(); } } }, { path: '/sign-up', name: 'SignUp', component: SignUp, meta: { title: '注册', requiresAuth: false } }, { path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFoundView, meta: { title: '页面未找到', requiresAuth: false } } ]; const router = createRouter({ history: createWebHistory(), routes }) // 全局前置守卫 router.beforeEach((to, from, next) => { // 设置页面标题 document.title = to.meta.title ? `${to.meta.title} - AriStockAI` : 'AriStockAI'; // 权限检查 - 暂时注释未定义的permission调用 // permission.routeGuard(to, from, next); next(); // 直接放行 }); // 全局后置钩子 router.afterEach((to, from) => { console.log(`Route changed from ${from.name || 'null'} to ${to.name}`); }) export default router;