]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/app-routing.module.ts
Translated using Weblate (German)
[github/Chocobozzz/PeerTube.git] / client / src / app / app-routing.module.ts
... / ...
CommitLineData
1import { NgModule } from '@angular/core'
2import { RouteReuseStrategy, RouterModule, Routes, UrlMatchResult, UrlSegment } from '@angular/router'
3import { CustomReuseStrategy } from '@app/core/routing/custom-reuse-strategy'
4import { MenuGuards } from '@app/core/routing/menu-guard.service'
5import { POSSIBLE_LOCALES } from '@shared/core-utils/i18n'
6import { HomepageRedirectComponent, MetaGuard, PreloadSelectedModulesList } from './core'
7import { EmptyComponent } from './empty.component'
8import { USER_USERNAME_REGEX_CHARACTERS } from './shared/form-validators/user-validators'
9import { ActorRedirectGuard } from './shared/shared-main'
10
11const 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 data: {
100 meta: {
101 title: $localize`Upload a video`
102 }
103 }
104 },
105 {
106 path: 'videos/update/:uuid',
107 loadChildren: () => import('@app/+videos/+video-edit/video-update.module').then(m => m.VideoUpdateModule),
108 data: {
109 meta: {
110 title: $localize`Edit a video`
111 }
112 }
113 },
114
115 {
116 path: 'videos/watch/playlist',
117 redirectTo: 'w/p'
118 },
119 {
120 path: 'videos/watch',
121 redirectTo: 'w'
122 },
123 {
124 path: 'w',
125 loadChildren: () => import('@app/+videos/+video-watch/video-watch.module').then(m => m.VideoWatchModule),
126 data: {
127 preload: 5000
128 }
129 },
130 {
131 path: 'videos',
132 loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule),
133 canActivateChild: [ MetaGuard ]
134 },
135 {
136 path: 'video-playlists/watch',
137 redirectTo: 'videos/watch/playlist'
138 },
139
140 {
141 path: 'remote-interaction',
142 loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule),
143 canActivateChild: [ MetaGuard ]
144 },
145
146 {
147 path: 'studio',
148 loadChildren: () => import('./+video-studio/video-studio.module').then(m => m.VideoStudioModule),
149 canActivateChild: [ MetaGuard ]
150 },
151
152 // Matches /@:actorName
153 {
154 matcher: (url): UrlMatchResult => {
155 const regex = new RegExp(`^@(${USER_USERNAME_REGEX_CHARACTERS}+)$`)
156 if (url.length !== 1) return null
157
158 const matchResult = url[0].path.match(regex)
159 if (!matchResult) return null
160
161 return {
162 consumed: url,
163 posParams: {
164 actorName: new UrlSegment(matchResult[1], {})
165 }
166 }
167 },
168 pathMatch: 'full',
169 canActivate: [ ActorRedirectGuard ],
170 component: EmptyComponent
171 },
172
173 {
174 path: '',
175 component: HomepageRedirectComponent
176 }
177]
178
179// Avoid 404 when changing language
180for (const locale of POSSIBLE_LOCALES) {
181 routes.push({
182 path: locale,
183 component: HomepageRedirectComponent
184 })
185}
186
187routes.push({
188 path: '**',
189 loadChildren: () => import('./+page-not-found/page-not-found.module').then(m => m.PageNotFoundModule)
190})
191
192@NgModule({
193 imports: [
194 RouterModule.forRoot(routes, {
195 useHash: Boolean(history.pushState) === false,
196 // Redefined in app component
197 scrollPositionRestoration: 'disabled',
198 preloadingStrategy: PreloadSelectedModulesList,
199 anchorScrolling: 'disabled'
200 })
201 ],
202 providers: [
203 MenuGuards.guards,
204 PreloadSelectedModulesList,
205 { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
206 ],
207 exports: [ RouterModule ]
208})
209export class AppRoutingModule {}