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 { 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 ]
62 loadChildren: () => import('./+about/about.module').then(m => m.AboutModule),
63 canActivateChild: [ MetaGuard ]
67 loadChildren: () => import('./+signup/+register/register.module').then(m => m.RegisterModule),
68 canActivateChild: [ MetaGuard ]
71 path: 'reset-password',
72 loadChildren: () => import('./+reset-password/reset-password.module').then(m => m.ResetPasswordModule),
73 canActivateChild: [ MetaGuard ]
77 loadChildren: () => import('./+login/login.module').then(m => m.LoginModule),
78 canActivateChild: [ MetaGuard ]
82 loadChildren: () => import('./+search/search.module').then(m => m.SearchModule),
83 canActivateChild: [ MetaGuard ]
87 path: 'videos/upload',
88 loadChildren: () => import('@app/+videos/+video-edit/video-add.module').then(m => m.VideoAddModule),
91 title: $localize`Upload a video`
96 path: 'videos/update/:uuid',
97 loadChildren: () => import('@app/+videos/+video-edit/video-update.module').then(m => m.VideoUpdateModule),
100 title: $localize`Edit a video`
106 path: 'videos/watch/playlist',
110 path: 'videos/watch',
115 loadChildren: () => import('@app/+videos/+video-watch/video-watch.module').then(m => m.VideoWatchModule),
122 loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule),
123 canActivateChild: [ MetaGuard ]
126 path: 'video-playlists/watch',
127 redirectTo: 'videos/watch/playlist'
131 path: 'remote-interaction',
132 loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule),
133 canActivateChild: [ MetaGuard ]
136 // Matches /@:actorName
138 matcher: (url): UrlMatchResult => {
139 const regex = new RegExp(`^@(${USER_USERNAME_REGEX_CHARACTERS}+)$`)
140 if (url.length !== 1) return null
142 const matchResult = url[0].path.match(regex)
143 if (!matchResult) return null
148 actorName: new UrlSegment(matchResult[1], {})
153 canActivate: [ ActorRedirectGuard ],
154 component: EmptyComponent
159 component: EmptyComponent // Avoid 404, app component will redirect dynamically
163 // Avoid 404 when changing language
164 for (const locale of POSSIBLE_LOCALES) {
167 component: EmptyComponent
173 loadChildren: () => import('./+page-not-found/page-not-found.module').then(m => m.PageNotFoundModule)
178 RouterModule.forRoot(routes, {
179 useHash: Boolean(history.pushState) === false,
180 scrollPositionRestoration: 'disabled',
181 preloadingStrategy: PreloadSelectedModulesList,
182 anchorScrolling: 'disabled'
187 PreloadSelectedModulesList,
188 { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
190 exports: [ RouterModule ]
192 export class AppRoutingModule {}