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 ]
41 loadChildren: () => import('./+accounts/accounts.module').then(m => m.AccountsModule),
42 canActivateChild: [ MetaGuard ]
46 loadChildren: () => import('./+video-channels/video-channels.module').then(m => m.VideoChannelsModule),
47 canActivateChild: [ MetaGuard ]
51 loadChildren: () => import('./+about/about.module').then(m => m.AboutModule),
52 canActivateChild: [ MetaGuard ]
56 loadChildren: () => import('./+signup/+register/register.module').then(m => m.RegisterModule),
57 canActivateChild: [ MetaGuard ]
60 path: 'reset-password',
61 loadChildren: () => import('./+reset-password/reset-password.module').then(m => m.ResetPasswordModule),
62 canActivateChild: [ MetaGuard ]
66 loadChildren: () => import('./+login/login.module').then(m => m.LoginModule),
67 canActivateChild: [ MetaGuard ]
71 loadChildren: () => import('./+search/search.module').then(m => m.SearchModule),
72 canActivateChild: [ MetaGuard ]
76 loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule),
77 canActivateChild: [ MetaGuard ]
80 path: 'remote-interaction',
81 loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule),
82 canActivateChild: [ MetaGuard ]
85 path: 'video-playlists/watch',
86 redirectTo: 'videos/watch/playlist'
93 path: 'video-channels',
97 matcher: (url): UrlMatchResult => {
98 // Matches /@:actorName
99 const regex = new RegExp(`^@(${USER_USERNAME_REGEX_CHARACTERS}+)$`)
100 if (url.length !== 1) return null
102 const matchResult = url[0].path.match(regex)
103 if (!matchResult) return null
108 actorName: new UrlSegment(matchResult[1], {})
113 canActivate: [ ActorRedirectGuard ],
114 component: EmptyComponent
118 component: EmptyComponent // Avoid 404, app component will redirect dynamically
122 // Avoid 404 when changing language
123 for (const locale of POSSIBLE_LOCALES) {
126 component: EmptyComponent
132 loadChildren: () => import('./+page-not-found/page-not-found.module').then(m => m.PageNotFoundModule)
137 RouterModule.forRoot(routes, {
138 useHash: Boolean(history.pushState) === false,
139 scrollPositionRestoration: 'disabled',
140 preloadingStrategy: PreloadSelectedModulesList,
141 anchorScrolling: 'disabled'
146 PreloadSelectedModulesList,
147 { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
149 exports: [ RouterModule ]
151 export class AppRoutingModule {}