]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app-routing.module.ts
Fix ngx loading bar deprecation
[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 // Matches /@:actorName
147 {
148 matcher: (url): UrlMatchResult => {
149 const regex = new RegExp(`^@(${USER_USERNAME_REGEX_CHARACTERS}+)$`)
150 if (url.length !== 1) return null
151
152 const matchResult = url[0].path.match(regex)
153 if (!matchResult) return null
154
155 return {
156 consumed: url,
157 posParams: {
158 actorName: new UrlSegment(matchResult[1], {})
159 }
160 }
161 },
162 pathMatch: 'full',
163 canActivate: [ ActorRedirectGuard ],
164 component: EmptyComponent
165 },
166
167 {
168 path: '',
169 component: HomepageRedirectComponent
170 }
171 ]
172
173 // Avoid 404 when changing language
174 for (const locale of POSSIBLE_LOCALES) {
175 routes.push({
176 path: locale,
177 component: HomepageRedirectComponent
178 })
179 }
180
181 routes.push({
182 path: '**',
183 loadChildren: () => import('./+page-not-found/page-not-found.module').then(m => m.PageNotFoundModule)
184 })
185
186 @NgModule({
187 imports: [
188 RouterModule.forRoot(routes, {
189 useHash: Boolean(history.pushState) === false,
190 // Redefined in app component
191 scrollPositionRestoration: 'disabled',
192 preloadingStrategy: PreloadSelectedModulesList,
193 anchorScrolling: 'disabled'
194 })
195 ],
196 providers: [
197 MenuGuards.guards,
198 PreloadSelectedModulesList,
199 { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
200 ],
201 exports: [ RouterModule ]
202 })
203 export class AppRoutingModule {}