app.routes.ts 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Route, Routes } from '@angular/router';
  2. import { authGuard } from './core/auth.guard';
  3. import { PageKind } from './core/models';
  4. import { PAGE_CATALOG } from './core/page-catalog';
  5. import { AppShellComponent } from './layout/app-shell.component';
  6. import { adminRoutes } from './admin/admin.routes';
  7. type ComponentLoader = Exclude<Route['loadComponent'], undefined>;
  8. const components: Record<PageKind, ComponentLoader> = {
  9. home: () => import('./features/home/home-page.component').then((module) => module.HomePageComponent),
  10. account: () => import('./features/home/account-page.component').then((module) => module.AccountPageComponent),
  11. article: () => import('./features/article/article-page.component').then((module) => module.ArticlePageComponent),
  12. login: () => import('./features/auth/login-page.component').then((module) => module.LoginPageComponent),
  13. resource: () => import('./features/resource/resource-page.component').then((module) => module.ResourcePageComponent),
  14. form: () => import('./features/form/form-page.component').then((module) => module.FormPageComponent),
  15. learning: () => import('./features/learning/learning-page.component').then((module) => module.LearningPageComponent),
  16. game: () => import('./features/game/game-page.component').then((module) => module.GamePageComponent),
  17. product: () => import('./features/product/product-page.component').then((module) => module.ProductPageComponent),
  18. productList: () => import('./features/product-list/product-list-page.component').then((module) => module.ProductListPageComponent),
  19. checkout: () => import('./features/checkout/checkout-page.component').then((module) => module.CheckoutPageComponent),
  20. order: () => import('./features/order/order-page.component').then((module) => module.OrderPageComponent),
  21. finance: () => import('./features/finance/finance-page.component').then((module) => module.FinancePageComponent),
  22. appointment: () => import('./features/appointment/appointment-page.component').then((module) => module.AppointmentPageComponent),
  23. courseCenter: () => import('./features/course-center/course-center-page.component').then((module) => module.CourseCenterPageComponent),
  24. studyRecords: () => import('./features/study-records/study-records-page.component').then((module) => module.StudyRecordsPageComponent),
  25. team: () => import('./features/team/team-page.component').then((module) => module.TeamPageComponent),
  26. merchant: () => import('./features/merchant/merchant-page.component').then((module) => module.MerchantPageComponent),
  27. webview: () => import('./features/webview/webview-page.component').then((module) => module.WebviewPageComponent),
  28. support: () => import('./features/support/support-page.component').then((module) => module.SupportPageComponent),
  29. supportFeedback: () => import('./features/support/support-feedback-page.component').then((module) => module.SupportFeedbackPageComponent),
  30. };
  31. const readingSetup: ComponentLoader = () => import('./features/english-reading/reading-setup.component').then((module) => module.ReadingSetupComponent);
  32. const migratedRoutes: Routes = PAGE_CATALOG.map((meta): Route => ({
  33. path: meta.path,
  34. loadComponent: meta.path === 'pages/iframe/index' ? readingSetup : components[meta.kind],
  35. canActivate: meta.auth ? [authGuard] : undefined,
  36. data: { meta },
  37. }));
  38. export const routes: Routes = [
  39. ...adminRoutes,
  40. {
  41. path: '',
  42. component: AppShellComponent,
  43. children: [
  44. { path: '', pathMatch: 'full', redirectTo: 'pages/home/index' },
  45. ...migratedRoutes,
  46. {
  47. path: 'english',
  48. loadComponent: () => import('./features/english-reading/reading-home.component').then((module) => module.ReadingHomeComponent),
  49. data: { meta: { path: 'english', title: '英语AI助手', domain: 'learn', kind: 'learning', hideHeader: true, hideTabbar: true } },
  50. },
  51. {
  52. path: 'words/go-reading',
  53. loadComponent: readingSetup,
  54. canActivate: [authGuard],
  55. data: { meta: { path: 'words/go-reading', title: 'AI 阅读设置', domain: 'learn', kind: 'learning', hideHeader: true, hideTabbar: true } },
  56. },
  57. {
  58. path: 'words/reading',
  59. loadComponent: () => import('./features/english-reading/reading-exercise.component').then((module) => module.ReadingExerciseComponent),
  60. canActivate: [authGuard],
  61. data: { meta: { path: 'words/reading', title: '阅读练习', domain: 'learn', kind: 'learning', hideHeader: true, hideTabbar: true } },
  62. },
  63. {
  64. path: 'words/reading/pdf/:sid',
  65. loadComponent: () => import('./features/english-reading/reading-pdf.component').then((module) => module.ReadingPdfComponent),
  66. canActivate: [authGuard],
  67. data: { meta: { path: 'words/reading/pdf/:sid', title: '阅读打印', domain: 'learn', kind: 'learning', hideHeader: true, hideTabbar: true } },
  68. },
  69. { path: '**', redirectTo: 'pages/home/index' },
  70. ],
  71. },
  72. ];