]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app-routing.module.ts
Merge branch 'release/4.1.0' into develop
[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 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: 'video-editor',
148 loadChildren: () => import('./+video-editor/video-editor.module').then(m => m.VideoEditorModule),
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
180 for (const locale of POSSIBLE_LOCALES) {
181 routes.push({
182 path: locale,
183 component: HomepageRedirectComponent
184 })
185 }
186
187 routes.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 })
209 export class AppRoutingModule {}