import { Route, Routes } from '@angular/router'; import { authGuard } from './core/auth.guard'; import { PageKind } from './core/models'; import { PAGE_CATALOG } from './core/page-catalog'; import { AppShellComponent } from './layout/app-shell.component'; import { adminRoutes } from './admin/admin.routes'; type ComponentLoader = Exclude; const components: Record = { home: () => import('./features/home/home-page.component').then((module) => module.HomePageComponent), account: () => import('./features/home/account-page.component').then((module) => module.AccountPageComponent), article: () => import('./features/article/article-page.component').then((module) => module.ArticlePageComponent), login: () => import('./features/auth/login-page.component').then((module) => module.LoginPageComponent), resource: () => import('./features/resource/resource-page.component').then((module) => module.ResourcePageComponent), form: () => import('./features/form/form-page.component').then((module) => module.FormPageComponent), learning: () => import('./features/learning/learning-page.component').then((module) => module.LearningPageComponent), game: () => import('./features/game/game-page.component').then((module) => module.GamePageComponent), product: () => import('./features/product/product-page.component').then((module) => module.ProductPageComponent), productList: () => import('./features/product-list/product-list-page.component').then((module) => module.ProductListPageComponent), checkout: () => import('./features/checkout/checkout-page.component').then((module) => module.CheckoutPageComponent), order: () => import('./features/order/order-page.component').then((module) => module.OrderPageComponent), finance: () => import('./features/finance/finance-page.component').then((module) => module.FinancePageComponent), appointment: () => import('./features/appointment/appointment-page.component').then((module) => module.AppointmentPageComponent), courseCenter: () => import('./features/course-center/course-center-page.component').then((module) => module.CourseCenterPageComponent), studyRecords: () => import('./features/study-records/study-records-page.component').then((module) => module.StudyRecordsPageComponent), team: () => import('./features/team/team-page.component').then((module) => module.TeamPageComponent), merchant: () => import('./features/merchant/merchant-page.component').then((module) => module.MerchantPageComponent), webview: () => import('./features/webview/webview-page.component').then((module) => module.WebviewPageComponent), support: () => import('./features/support/support-page.component').then((module) => module.SupportPageComponent), supportFeedback: () => import('./features/support/support-feedback-page.component').then((module) => module.SupportFeedbackPageComponent), }; const readingSetup: ComponentLoader = () => import('./features/english-reading/reading-setup.component').then((module) => module.ReadingSetupComponent); const migratedRoutes: Routes = PAGE_CATALOG.map((meta): Route => ({ path: meta.path, loadComponent: meta.path === 'pages/iframe/index' ? readingSetup : components[meta.kind], canActivate: meta.auth ? [authGuard] : undefined, data: { meta }, })); export const routes: Routes = [ ...adminRoutes, { path: '', component: AppShellComponent, children: [ { path: '', pathMatch: 'full', redirectTo: 'pages/home/index' }, ...migratedRoutes, { path: 'english', loadComponent: () => import('./features/english-reading/reading-home.component').then((module) => module.ReadingHomeComponent), data: { meta: { path: 'english', title: '英语AI助手', domain: 'learn', kind: 'learning', hideHeader: true, hideTabbar: true } }, }, { path: 'words/go-reading', loadComponent: readingSetup, canActivate: [authGuard], data: { meta: { path: 'words/go-reading', title: 'AI 阅读设置', domain: 'learn', kind: 'learning', hideHeader: true, hideTabbar: true } }, }, { path: 'words/reading', loadComponent: () => import('./features/english-reading/reading-exercise.component').then((module) => module.ReadingExerciseComponent), canActivate: [authGuard], data: { meta: { path: 'words/reading', title: '阅读练习', domain: 'learn', kind: 'learning', hideHeader: true, hideTabbar: true } }, }, { path: 'words/reading/pdf/:sid', loadComponent: () => import('./features/english-reading/reading-pdf.component').then((module) => module.ReadingPdfComponent), canActivate: [authGuard], data: { meta: { path: 'words/reading/pdf/:sid', title: '阅读打印', domain: 'learn', kind: 'learning', hideHeader: true, hideTabbar: true } }, }, { path: '**', redirectTo: 'pages/home/index' }, ], }, ];