1 import { NgModule } from '@angular/core'
2 import { RouteReuseStrategy, RouterModule, Routes, UrlMatchResult, UrlSegment } from '@angular/router'
3 import { CustomReuseStrategy } from '@app/core/routing/custom-reuse-strategy'
4 import { MenuGuards } from '@app/core/routing/menu-guard.service'
5 import { POSSIBLE_LOCALES } from '@shared/core-utils/i18n'
6 import { HomepageRedirectComponent, MetaGuard, PreloadSelectedModulesList } from './core'
7 import { EmptyComponent } from './empty.component'
8 import { USER_USERNAME_REGEX_CHARACTERS } from './shared/form-validators/user-validators'
9 import { ActorRedirectGuard } from './shared/shared-main'
11 const routes: Routes = [
14 canActivate: [ MenuGuards.close() ],
15 canDeactivate: [ MenuGuards.open() ],
16 loadChildren: () => import('./+admin/admin.module').then(m => m.AdminModule),
17 canActivateChild: [ MetaGuard ]
21 loadChildren: () => import('./+home/home.module').then(m => m.HomeModule),
22 canActivateChild: [ MetaGuard ]
26 loadChildren: () => import('./+my-account/my-account.module').then(m => m.MyAccountModule),
27 canActivateChild: [ MetaGuard ]
31 loadChildren: () => import('./+my-library/my-library.module').then(m => m.MyLibraryModule),
32 canActivateChild: [ MetaGuard ]
35 path: 'verify-account',
36 loadChildren: () => import('./+signup/+verify-account/verify-account.module').then(m => m.VerifyAccountModule),
37 canActivateChild: [ MetaGuard ]
46 loadChildren: () => import('./+accounts/accounts.module').then(m => m.AccountsModule),
47 canActivateChild: [ MetaGuard ]
51 path: 'video-channels',
56 loadChildren: () => import('./+video-channels/video-channels.module').then(m => m.VideoChannelsModule),
57 canActivateChild: [ MetaGuard ]
61 loadChildren: () => import('./+manage/manage.module').then(m => m.ManageModule),
62 canActivateChild: [ MetaGuard ]
66 loadChildren: () => import('./+plugin-pages/plugin-pages.module').then(m => m.PluginPagesModule),
67 canActivateChild: [ MetaGuard ]
72 loadChildren: () => import('./+about/about.module').then(m => m.AboutModule),
73 canActivateChild: [ MetaGuard ]
77 loadChildren: () => import('./+signup/+register/register.module').then(m => m.RegisterModule),
78 canActivateChild: [ MetaGuard ]
81 path: 'reset-password',
82 loadChildren: () => import('./+reset-password/reset-password.module').then(m => m.ResetPasswordModule),
83 canActivateChild: [ MetaGuard ]
87 loadChildren: () => import('./+login/login.module').then(m => m.LoginModule),
88 canActivateChild: [ MetaGuard ]
92 loadChildren: () => import('./+search/search.module').then(m => m.SearchModule),
93 canActivateChild: [ MetaGuard ]
97 path: 'videos/upload',
98 loadChildren: () => import('@app/+videos/+video-edit/video-add.module').then(m => m.VideoAddModule),
99 canActivateChild: [ MetaGuard ],
102 title: $localize`Upload a video`
107 path: 'videos/update/:uuid',
108 loadChildren: () => import('@app/+videos/+video-edit/video-update.module').then(m => m.VideoUpdateModule),
109 canActivateChild: [ MetaGuard ],
112 title: $localize`Edit a video`
118 path: 'videos/watch/playlist',
122 path: 'videos/watch',
127 loadChildren: () => import('@app/+videos/+video-watch/video-watch.module').then(m => m.VideoWatchModule),
134 loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule),
135 canActivateChild: [ MetaGuard ]
138 path: 'video-playlists/watch',
139 redirectTo: 'videos/watch/playlist'
143 path: 'remote-interaction',
144 loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule),
145 canActivateChild: [ MetaGuard ]
150 loadChildren: () => import('./+video-studio/video-studio.module').then(m => m.VideoStudioModule),
151 canActivateChild: [ MetaGuard ]
156 loadChildren: () => import('./+stats/stats.module').then(m => m.StatsModule),
157 canActivateChild: [ MetaGuard ]
160 // Matches /@:actorName
162 matcher: (url): UrlMatchResult => {
163 const regex = new RegExp(`^@(${USER_USERNAME_REGEX_CHARACTERS}+)$`)
164 if (url.length !== 1) return null
166 const matchResult = url[0].path.match(regex)
167 if (!matchResult) return null
172 actorName: new UrlSegment(matchResult[1], {})
177 canActivate: [ ActorRedirectGuard ],
178 component: EmptyComponent
183 component: HomepageRedirectComponent
187 // Avoid 404 when changing language
188 for (const locale of POSSIBLE_LOCALES) {
191 component: HomepageRedirectComponent
197 loadChildren: () => import('./+error-page/error-page.module').then(m => m.ErrorPageModule)
202 RouterModule.forRoot(routes, {
203 useHash: Boolean(history.pushState) === false,
204 // Redefined in app component
205 scrollPositionRestoration: 'disabled',
206 preloadingStrategy: PreloadSelectedModulesList,
207 anchorScrolling: 'disabled'
212 PreloadSelectedModulesList,
213 { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
215 exports: [ RouterModule ]
217 export class AppRoutingModule {}