]>
Commit | Line | Data |
---|---|---|
df98563e | 1 | import { NgModule } from '@angular/core' |
69e076dd | 2 | import { RouteReuseStrategy, RouterModule, Routes, UrlMatchResult, UrlSegment } from '@angular/router' |
489290b8 | 3 | import { CustomReuseStrategy } from '@app/core/routing/custom-reuse-strategy' |
3b20bdd6 | 4 | import { MenuGuards } from '@app/core/routing/menu-guard.service' |
d43c6b1f | 5 | import { POSSIBLE_LOCALES } from '@shared/core-utils/i18n' |
fc21ef5c | 6 | import { HomepageRedirectComponent, MetaGuard, PreloadSelectedModulesList } from './core' |
1942f11d | 7 | import { EmptyComponent } from './empty.component' |
012580d9 C |
8 | import { USER_USERNAME_REGEX_CHARACTERS } from './shared/form-validators/user-validators' |
9 | import { ActorRedirectGuard } from './shared/shared-main' | |
693b1aba C |
10 | |
11 | const 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 | }, |
a37e9e74 | 59 | { |
60 | path: 'manage', | |
61 | loadChildren: () => import('./+manage/manage.module').then(m => m.ManageModule), | |
62 | canActivateChild: [ MetaGuard ] | |
63 | }, | |
d63e6d46 C |
64 | { |
65 | path: 'p', | |
66 | loadChildren: () => import('./+plugin-pages/plugin-pages.module').then(m => m.PluginPagesModule), | |
67 | canActivateChild: [ MetaGuard ] | |
68 | }, | |
69 | ||
78f912ed C |
70 | { |
71 | path: 'about', | |
0f01a8ba C |
72 | loadChildren: () => import('./+about/about.module').then(m => m.AboutModule), |
73 | canActivateChild: [ MetaGuard ] | |
78f912ed | 74 | }, |
b247a132 C |
75 | { |
76 | path: 'signup', | |
0f01a8ba C |
77 | loadChildren: () => import('./+signup/+register/register.module').then(m => m.RegisterModule), |
78 | canActivateChild: [ MetaGuard ] | |
b247a132 | 79 | }, |
1942f11d C |
80 | { |
81 | path: 'reset-password', | |
0f01a8ba C |
82 | loadChildren: () => import('./+reset-password/reset-password.module').then(m => m.ResetPasswordModule), |
83 | canActivateChild: [ MetaGuard ] | |
1942f11d C |
84 | }, |
85 | { | |
86 | path: 'login', | |
0f01a8ba C |
87 | loadChildren: () => import('./+login/login.module').then(m => m.LoginModule), |
88 | canActivateChild: [ MetaGuard ] | |
1942f11d C |
89 | }, |
90 | { | |
91 | path: 'search', | |
0f01a8ba C |
92 | loadChildren: () => import('./+search/search.module').then(m => m.SearchModule), |
93 | canActivateChild: [ MetaGuard ] | |
1942f11d | 94 | }, |
a1eda903 | 95 | |
1942f11d | 96 | { |
a1eda903 C |
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 | } | |
1942f11d | 104 | }, |
d43c6b1f | 105 | { |
a1eda903 C |
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: { | |
8e08d415 | 127 | preload: 5000 |
a1eda903 C |
128 | } |
129 | }, | |
130 | { | |
131 | path: 'videos', | |
132 | loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule), | |
0f01a8ba | 133 | canActivateChild: [ MetaGuard ] |
d43c6b1f | 134 | }, |
0bd6d35f C |
135 | { |
136 | path: 'video-playlists/watch', | |
137 | redirectTo: 'videos/watch/playlist' | |
138 | }, | |
a1eda903 | 139 | |
ff8c5ccf | 140 | { |
a1eda903 C |
141 | path: 'remote-interaction', |
142 | loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule), | |
143 | canActivateChild: [ MetaGuard ] | |
ff8c5ccf | 144 | }, |
a1eda903 C |
145 | |
146 | // Matches /@:actorName | |
ff8c5ccf | 147 | { |
69e076dd | 148 | matcher: (url): UrlMatchResult => { |
012580d9 C |
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], {}) | |
69e076dd K |
159 | } |
160 | } | |
69e076dd | 161 | }, |
012580d9 C |
162 | pathMatch: 'full', |
163 | canActivate: [ ActorRedirectGuard ], | |
164 | component: EmptyComponent | |
ff8c5ccf | 165 | }, |
a1eda903 | 166 | |
b889cdb2 C |
167 | { |
168 | path: '', | |
fc21ef5c | 169 | component: HomepageRedirectComponent |
4b4f22fc | 170 | } |
df98563e | 171 | ] |
693b1aba | 172 | |
ca00baa7 C |
173 | // Avoid 404 when changing language |
174 | for (const locale of POSSIBLE_LOCALES) { | |
175 | routes.push({ | |
176 | path: locale, | |
fc21ef5c | 177 | component: HomepageRedirectComponent |
ca00baa7 C |
178 | }) |
179 | } | |
180 | ||
181 | routes.push({ | |
182 | path: '**', | |
183 | loadChildren: () => import('./+page-not-found/page-not-found.module').then(m => m.PageNotFoundModule) | |
184 | }) | |
185 | ||
693b1aba | 186 | @NgModule({ |
04de542a C |
187 | imports: [ |
188 | RouterModule.forRoot(routes, { | |
189 | useHash: Boolean(history.pushState) === false, | |
dd24f1bb | 190 | // Redefined in app component |
489290b8 | 191 | scrollPositionRestoration: 'disabled', |
07a98236 | 192 | preloadingStrategy: PreloadSelectedModulesList, |
489290b8 | 193 | anchorScrolling: 'disabled' |
04de542a C |
194 | }) |
195 | ], | |
901637bb | 196 | providers: [ |
3b20bdd6 | 197 | MenuGuards.guards, |
489290b8 C |
198 | PreloadSelectedModulesList, |
199 | { provide: RouteReuseStrategy, useClass: CustomReuseStrategy } | |
901637bb | 200 | ], |
693b1aba C |
201 | exports: [ RouterModule ] |
202 | }) | |
203 | export class AppRoutingModule {} |