]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app-routing.module.ts
Improve remote runner config UX
[github/Chocobozzz/PeerTube.git] / client / src / app / app-routing.module.ts
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'
10
11 const routes: Routes = [
12 {
13 path: 'admin',
14 canActivate: [ MenuGuards.close() ],
15 canDeactivate: [ MenuGuards.open() ],
16 loadChildren: () => import('./+admin/admin.module').then(m => m.AdminModule),
17 canActivateChild: [ MetaGuard ]
18 },
19 {
20 path: 'home',
21 loadChildren: () => import('./+home/home.module').then(m => m.HomeModule),
22 canActivateChild: [ MetaGuard ]
23 },
24 {
25 path: 'my-account',
26 loadChildren: () => import('./+my-account/my-account.module').then(m => m.MyAccountModule),
27 canActivateChild: [ MetaGuard ]
28 },
29 {
30 path: 'my-library',
31 loadChildren: () => import('./+my-library/my-library.module').then(m => m.MyLibraryModule),
32 canActivateChild: [ MetaGuard ]
33 },
34 {
35 path: 'verify-account',
36 loadChildren: () => import('./+signup/+verify-account/verify-account.module').then(m => m.VerifyAccountModule),
37 canActivateChild: [ MetaGuard ]
38 },
39
40 {
41 path: 'accounts',
42 redirectTo: 'a'
43 },
44 {
45 path: 'a',
46 loadChildren: () => import('./+accounts/accounts.module').then(m => m.AccountsModule),
47 canActivateChild: [ MetaGuard ]
48 },
49
50 {
51 path: 'video-channels',
52 redirectTo: 'c'
53 },
54 {
55 path: 'c',
56 loadChildren: () => import('./+video-channels/video-channels.module').then(m => m.VideoChannelsModule),
57 canActivateChild: [ MetaGuard ]
58 },
59 {
60 path: 'manage',
61 loadChildren: () => import('./+manage/manage.module').then(m => m.ManageModule),
62 canActivateChild: [ MetaGuard ]
63 },
64 {
65 path: 'p',
66 loadChildren: () => import('./+plugin-pages/plugin-pages.module').then(m => m.PluginPagesModule),
67 canActivateChild: [ MetaGuard ]
68 },
69
70 {
71 path: 'about',
72 loadChildren: () => import('./+about/about.module').then(m => m.AboutModule),
73 canActivateChild: [ MetaGuard ]
74 },
75 {
76 path: 'signup',
77 loadChildren: () => import('./+signup/+register/register.module').then(m => m.RegisterModule),
78 canActivateChild: [ MetaGuard ]
79 },
80 {
81 path: 'reset-password',
82 loadChildren: () => import('./+reset-password/reset-password.module').then(m => m.ResetPasswordModule),
83 canActivateChild: [ MetaGuard ]
84 },
85 {
86 path: 'login',
87 loadChildren: () => import('./+login/login.module').then(m => m.LoginModule),
88 canActivateChild: [ MetaGuard ]
89 },
90 {
91 path: 'search',
92 loadChildren: () => import('./+search/search.module').then(m => m.SearchModule),
93 canActivateChild: [ MetaGuard ]
94 },
95
96 {
97 path: 'videos/upload',
98 loadChildren: () => import('@app/+videos/+video-edit/video-add.module').then(m => m.VideoAddModule),
99 canActivateChild: [ MetaGuard ],
100 data: {
101 meta: {
102 title: $localize`Upload a video`
103 }
104 }
105 },
106 {
107 path: 'videos/update/:uuid',
108 loadChildren: () => import('@app/+videos/+video-edit/video-update.module').then(m => m.VideoUpdateModule),
109 canActivateChild: [ MetaGuard ],
110 data: {
111 meta: {
112 title: $localize`Edit a video`
113 }
114 }
115 },
116
117 {
118 path: 'videos/watch/playlist',
119 redirectTo: 'w/p'
120 },
121 {
122 path: 'videos/watch',
123 redirectTo: 'w'
124 },
125 {
126 path: 'w',
127 loadChildren: () => import('@app/+videos/+video-watch/video-watch.module').then(m => m.VideoWatchModule),
128 data: {
129 preload: 5000
130 }
131 },
132 {
133 path: 'videos',
134 loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule),
135 canActivateChild: [ MetaGuard ]
136 },
137 {
138 path: 'video-playlists/watch',
139 redirectTo: 'videos/watch/playlist'
140 },
141
142 {
143 path: 'remote-interaction',
144 loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule),
145 canActivateChild: [ MetaGuard ]
146 },
147
148 {
149 path: 'studio',
150 loadChildren: () => import('./+video-studio/video-studio.module').then(m => m.VideoStudioModule),
151 canActivateChild: [ MetaGuard ]
152 },
153
154 {
155 path: 'stats',
156 loadChildren: () => import('./+stats/stats.module').then(m => m.StatsModule),
157 canActivateChild: [ MetaGuard ]
158 },
159
160 // Matches /@:actorName
161 {
162 matcher: (url): UrlMatchResult => {
163 const regex = new RegExp(`^@(${USER_USERNAME_REGEX_CHARACTERS}+)$`)
164 if (url.length !== 1) return null
165
166 const matchResult = url[0].path.match(regex)
167 if (!matchResult) return null
168
169 return {
170 consumed: url,
171 posParams: {
172 actorName: new UrlSegment(matchResult[1], {})
173 }
174 }
175 },
176 pathMatch: 'full',
177 canActivate: [ ActorRedirectGuard ],
178 component: EmptyComponent
179 },
180
181 {
182 path: '',
183 component: HomepageRedirectComponent
184 }
185 ]
186
187 // Avoid 404 when changing language
188 for (const locale of POSSIBLE_LOCALES) {
189 routes.push({
190 path: locale,
191 component: HomepageRedirectComponent
192 })
193 }
194
195 routes.push({
196 path: '**',
197 loadChildren: () => import('./+error-page/error-page.module').then(m => m.ErrorPageModule)
198 })
199
200 @NgModule({
201 imports: [
202 RouterModule.forRoot(routes, {
203 useHash: Boolean(history.pushState) === false,
204 // Redefined in app component
205 scrollPositionRestoration: 'disabled',
206 preloadingStrategy: PreloadSelectedModulesList,
207 anchorScrolling: 'disabled'
208 })
209 ],
210 providers: [
211 MenuGuards.guards,
212 PreloadSelectedModulesList,
213 { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
214 ],
215 exports: [ RouterModule ]
216 })
217 export class AppRoutingModule {}