]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app-routing.module.ts
444b6f13494b7e8ada2560aced9d7a7605ea63b2
[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 { 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 path: 'a',
41 loadChildren: () => import('./+accounts/accounts.module').then(m => m.AccountsModule),
42 canActivateChild: [ MetaGuard ]
43 },
44 {
45 path: 'c',
46 loadChildren: () => import('./+video-channels/video-channels.module').then(m => m.VideoChannelsModule),
47 canActivateChild: [ MetaGuard ]
48 },
49 {
50 path: 'about',
51 loadChildren: () => import('./+about/about.module').then(m => m.AboutModule),
52 canActivateChild: [ MetaGuard ]
53 },
54 {
55 path: 'signup',
56 loadChildren: () => import('./+signup/+register/register.module').then(m => m.RegisterModule),
57 canActivateChild: [ MetaGuard ]
58 },
59 {
60 path: 'reset-password',
61 loadChildren: () => import('./+reset-password/reset-password.module').then(m => m.ResetPasswordModule),
62 canActivateChild: [ MetaGuard ]
63 },
64 {
65 path: 'login',
66 loadChildren: () => import('./+login/login.module').then(m => m.LoginModule),
67 canActivateChild: [ MetaGuard ]
68 },
69 {
70 path: 'search',
71 loadChildren: () => import('./+search/search.module').then(m => m.SearchModule),
72 canActivateChild: [ MetaGuard ]
73 },
74 {
75 path: 'videos',
76 loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule),
77 canActivateChild: [ MetaGuard ]
78 },
79 {
80 path: 'remote-interaction',
81 loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule),
82 canActivateChild: [ MetaGuard ]
83 },
84 {
85 path: 'video-playlists/watch',
86 redirectTo: 'videos/watch/playlist'
87 },
88 {
89 path: 'accounts',
90 redirectTo: 'a'
91 },
92 {
93 path: 'video-channels',
94 redirectTo: 'c'
95 },
96 {
97 matcher: (url): UrlMatchResult => {
98 // Matches /@:actorName
99 const regex = new RegExp(`^@(${USER_USERNAME_REGEX_CHARACTERS}+)$`)
100 if (url.length !== 1) return null
101
102 const matchResult = url[0].path.match(regex)
103 if (!matchResult) return null
104
105 return {
106 consumed: url,
107 posParams: {
108 actorName: new UrlSegment(matchResult[1], {})
109 }
110 }
111 },
112 pathMatch: 'full',
113 canActivate: [ ActorRedirectGuard ],
114 component: EmptyComponent
115 },
116 {
117 path: '',
118 component: EmptyComponent // Avoid 404, app component will redirect dynamically
119 }
120 ]
121
122 // Avoid 404 when changing language
123 for (const locale of POSSIBLE_LOCALES) {
124 routes.push({
125 path: locale,
126 component: EmptyComponent
127 })
128 }
129
130 routes.push({
131 path: '**',
132 loadChildren: () => import('./+page-not-found/page-not-found.module').then(m => m.PageNotFoundModule)
133 })
134
135 @NgModule({
136 imports: [
137 RouterModule.forRoot(routes, {
138 useHash: Boolean(history.pushState) === false,
139 scrollPositionRestoration: 'disabled',
140 preloadingStrategy: PreloadSelectedModulesList,
141 anchorScrolling: 'disabled'
142 })
143 ],
144 providers: [
145 MenuGuards.guards,
146 PreloadSelectedModulesList,
147 { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
148 ],
149 exports: [ RouterModule ]
150 })
151 export class AppRoutingModule {}