]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/app-routing.module.ts
Add ability to redirect users on external auth
[github/Chocobozzz/PeerTube.git] / client / src / app / app-routing.module.ts
CommitLineData
df98563e 1import { NgModule } from '@angular/core'
69e076dd 2import { RouteReuseStrategy, RouterModule, Routes, UrlMatchResult, UrlSegment } from '@angular/router'
489290b8 3import { CustomReuseStrategy } from '@app/core/routing/custom-reuse-strategy'
3b20bdd6 4import { MenuGuards } from '@app/core/routing/menu-guard.service'
d43c6b1f 5import { POSSIBLE_LOCALES } from '@shared/core-utils/i18n'
fc21ef5c 6import { HomepageRedirectComponent, MetaGuard, PreloadSelectedModulesList } from './core'
1942f11d 7import { EmptyComponent } from './empty.component'
012580d9
C
8import { USER_USERNAME_REGEX_CHARACTERS } from './shared/form-validators/user-validators'
9import { ActorRedirectGuard } from './shared/shared-main'
693b1aba
C
10
11const routes: Routes = [
4b4f22fc
C
12 {
13 path: 'admin',
3b20bdd6
RK
14 canActivate: [ MenuGuards.close() ],
15 canDeactivate: [ MenuGuards.open() ],
0f01a8ba
C
16 loadChildren: () => import('./+admin/admin.module').then(m => m.AdminModule),
17 canActivateChild: [ MetaGuard ]
4b4f22fc 18 },
2539932e
C
19 {
20 path: 'home',
012580d9
C
21 loadChildren: () => import('./+home/home.module').then(m => m.HomeModule),
22 canActivateChild: [ MetaGuard ]
4b4f22fc
C
23 },
24 {
25 path: 'my-account',
0f01a8ba
C
26 loadChildren: () => import('./+my-account/my-account.module').then(m => m.MyAccountModule),
27 canActivateChild: [ MetaGuard ]
4b4f22fc 28 },
17119e4a
C
29 {
30 path: 'my-library',
0f01a8ba
C
31 loadChildren: () => import('./+my-library/my-library.module').then(m => m.MyLibraryModule),
32 canActivateChild: [ MetaGuard ]
17119e4a 33 },
d9eaee39
JM
34 {
35 path: 'verify-account',
0f01a8ba
C
36 loadChildren: () => import('./+signup/+verify-account/verify-account.module').then(m => m.VerifyAccountModule),
37 canActivateChild: [ MetaGuard ]
d9eaee39 38 },
a1eda903
C
39
40 {
41 path: 'accounts',
42 redirectTo: 'a'
43 },
4b4f22fc 44 {
71887396 45 path: 'a',
0f01a8ba
C
46 loadChildren: () => import('./+accounts/accounts.module').then(m => m.AccountsModule),
47 canActivateChild: [ MetaGuard ]
4b4f22fc 48 },
a1eda903
C
49
50 {
51 path: 'video-channels',
52 redirectTo: 'c'
53 },
4b4f22fc 54 {
71887396 55 path: 'c',
0f01a8ba
C
56 loadChildren: () => import('./+video-channels/video-channels.module').then(m => m.VideoChannelsModule),
57 canActivateChild: [ MetaGuard ]
a51bad1a 58 },
a1eda903 59
78f912ed
C
60 {
61 path: 'about',
0f01a8ba
C
62 loadChildren: () => import('./+about/about.module').then(m => m.AboutModule),
63 canActivateChild: [ MetaGuard ]
78f912ed 64 },
b247a132
C
65 {
66 path: 'signup',
0f01a8ba
C
67 loadChildren: () => import('./+signup/+register/register.module').then(m => m.RegisterModule),
68 canActivateChild: [ MetaGuard ]
b247a132 69 },
1942f11d
C
70 {
71 path: 'reset-password',
0f01a8ba
C
72 loadChildren: () => import('./+reset-password/reset-password.module').then(m => m.ResetPasswordModule),
73 canActivateChild: [ MetaGuard ]
1942f11d
C
74 },
75 {
76 path: 'login',
0f01a8ba
C
77 loadChildren: () => import('./+login/login.module').then(m => m.LoginModule),
78 canActivateChild: [ MetaGuard ]
1942f11d
C
79 },
80 {
81 path: 'search',
0f01a8ba
C
82 loadChildren: () => import('./+search/search.module').then(m => m.SearchModule),
83 canActivateChild: [ MetaGuard ]
1942f11d 84 },
a1eda903 85
1942f11d 86 {
a1eda903
C
87 path: 'videos/upload',
88 loadChildren: () => import('@app/+videos/+video-edit/video-add.module').then(m => m.VideoAddModule),
89 data: {
90 meta: {
91 title: $localize`Upload a video`
92 }
93 }
1942f11d 94 },
d43c6b1f 95 {
a1eda903
C
96 path: 'videos/update/:uuid',
97 loadChildren: () => import('@app/+videos/+video-edit/video-update.module').then(m => m.VideoUpdateModule),
98 data: {
99 meta: {
100 title: $localize`Edit a video`
101 }
102 }
103 },
104
105 {
106 path: 'videos/watch/playlist',
107 redirectTo: 'w/p'
108 },
109 {
110 path: 'videos/watch',
111 redirectTo: 'w'
112 },
113 {
114 path: 'w',
115 loadChildren: () => import('@app/+videos/+video-watch/video-watch.module').then(m => m.VideoWatchModule),
116 data: {
8e08d415 117 preload: 5000
a1eda903
C
118 }
119 },
120 {
121 path: 'videos',
122 loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule),
0f01a8ba 123 canActivateChild: [ MetaGuard ]
d43c6b1f 124 },
0bd6d35f
C
125 {
126 path: 'video-playlists/watch',
127 redirectTo: 'videos/watch/playlist'
128 },
a1eda903 129
ff8c5ccf 130 {
a1eda903
C
131 path: 'remote-interaction',
132 loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule),
133 canActivateChild: [ MetaGuard ]
ff8c5ccf 134 },
a1eda903
C
135
136 // Matches /@:actorName
ff8c5ccf 137 {
69e076dd 138 matcher: (url): UrlMatchResult => {
012580d9
C
139 const regex = new RegExp(`^@(${USER_USERNAME_REGEX_CHARACTERS}+)$`)
140 if (url.length !== 1) return null
141
142 const matchResult = url[0].path.match(regex)
143 if (!matchResult) return null
144
145 return {
146 consumed: url,
147 posParams: {
148 actorName: new UrlSegment(matchResult[1], {})
69e076dd
K
149 }
150 }
69e076dd 151 },
012580d9
C
152 pathMatch: 'full',
153 canActivate: [ ActorRedirectGuard ],
154 component: EmptyComponent
ff8c5ccf 155 },
a1eda903 156
b889cdb2
C
157 {
158 path: '',
fc21ef5c 159 component: HomepageRedirectComponent
4b4f22fc 160 }
df98563e 161]
693b1aba 162
ca00baa7
C
163// Avoid 404 when changing language
164for (const locale of POSSIBLE_LOCALES) {
165 routes.push({
166 path: locale,
fc21ef5c 167 component: HomepageRedirectComponent
ca00baa7
C
168 })
169}
170
171routes.push({
172 path: '**',
173 loadChildren: () => import('./+page-not-found/page-not-found.module').then(m => m.PageNotFoundModule)
174})
175
693b1aba 176@NgModule({
04de542a
C
177 imports: [
178 RouterModule.forRoot(routes, {
179 useHash: Boolean(history.pushState) === false,
dd24f1bb 180 // Redefined in app component
489290b8 181 scrollPositionRestoration: 'disabled',
07a98236 182 preloadingStrategy: PreloadSelectedModulesList,
489290b8 183 anchorScrolling: 'disabled'
04de542a
C
184 })
185 ],
901637bb 186 providers: [
3b20bdd6 187 MenuGuards.guards,
489290b8
C
188 PreloadSelectedModulesList,
189 { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
901637bb 190 ],
693b1aba
C
191 exports: [ RouterModule ]
192})
193export class AppRoutingModule {}