]>
Commit | Line | Data |
---|---|---|
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 | { | |
61 | path: 'about', | |
62 | loadChildren: () => import('./+about/about.module').then(m => m.AboutModule), | |
63 | canActivateChild: [ MetaGuard ] | |
64 | }, | |
65 | { | |
66 | path: 'signup', | |
67 | loadChildren: () => import('./+signup/+register/register.module').then(m => m.RegisterModule), | |
68 | canActivateChild: [ MetaGuard ] | |
69 | }, | |
70 | { | |
71 | path: 'reset-password', | |
72 | loadChildren: () => import('./+reset-password/reset-password.module').then(m => m.ResetPasswordModule), | |
73 | canActivateChild: [ MetaGuard ] | |
74 | }, | |
75 | { | |
76 | path: 'login', | |
77 | loadChildren: () => import('./+login/login.module').then(m => m.LoginModule), | |
78 | canActivateChild: [ MetaGuard ] | |
79 | }, | |
80 | { | |
81 | path: 'search', | |
82 | loadChildren: () => import('./+search/search.module').then(m => m.SearchModule), | |
83 | canActivateChild: [ MetaGuard ] | |
84 | }, | |
85 | ||
86 | { | |
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 | } | |
94 | }, | |
95 | { | |
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: { | |
117 | preload: 5000 | |
118 | } | |
119 | }, | |
120 | { | |
121 | path: 'videos', | |
122 | loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule), | |
123 | canActivateChild: [ MetaGuard ] | |
124 | }, | |
125 | { | |
126 | path: 'video-playlists/watch', | |
127 | redirectTo: 'videos/watch/playlist' | |
128 | }, | |
129 | ||
130 | { | |
131 | path: 'remote-interaction', | |
132 | loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule), | |
133 | canActivateChild: [ MetaGuard ] | |
134 | }, | |
135 | ||
136 | // Matches /@:actorName | |
137 | { | |
138 | matcher: (url): UrlMatchResult => { | |
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], {}) | |
149 | } | |
150 | } | |
151 | }, | |
152 | pathMatch: 'full', | |
153 | canActivate: [ ActorRedirectGuard ], | |
154 | component: EmptyComponent | |
155 | }, | |
156 | ||
157 | { | |
158 | path: '', | |
159 | component: HomepageRedirectComponent | |
160 | } | |
161 | ] | |
162 | ||
163 | // Avoid 404 when changing language | |
164 | for (const locale of POSSIBLE_LOCALES) { | |
165 | routes.push({ | |
166 | path: locale, | |
167 | component: HomepageRedirectComponent | |
168 | }) | |
169 | } | |
170 | ||
171 | routes.push({ | |
172 | path: '**', | |
173 | loadChildren: () => import('./+page-not-found/page-not-found.module').then(m => m.PageNotFoundModule) | |
174 | }) | |
175 | ||
176 | @NgModule({ | |
177 | imports: [ | |
178 | RouterModule.forRoot(routes, { | |
179 | useHash: Boolean(history.pushState) === false, | |
180 | // Redefined in app component | |
181 | scrollPositionRestoration: 'disabled', | |
182 | preloadingStrategy: PreloadSelectedModulesList, | |
183 | anchorScrolling: 'disabled' | |
184 | }) | |
185 | ], | |
186 | providers: [ | |
187 | MenuGuards.guards, | |
188 | PreloadSelectedModulesList, | |
189 | { provide: RouteReuseStrategy, useClass: CustomReuseStrategy } | |
190 | ], | |
191 | exports: [ RouterModule ] | |
192 | }) | |
193 | export class AppRoutingModule {} |