]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app-routing.module.ts
Make /a and /c default URLs for accounts and channels
[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 { PreloadSelectedModulesList } from './core'
7 import { EmptyComponent } from './empty.component'
8 import { RootComponent } from './root.component'
9
10 const routes: Routes = [
11 {
12 path: 'admin',
13 canActivate: [ MenuGuards.close() ],
14 canDeactivate: [ MenuGuards.open() ],
15 loadChildren: () => import('./+admin/admin.module').then(m => m.AdminModule)
16 },
17 {
18 path: 'my-account',
19 loadChildren: () => import('./+my-account/my-account.module').then(m => m.MyAccountModule)
20 },
21 {
22 path: 'my-library',
23 loadChildren: () => import('./+my-library/my-library.module').then(m => m.MyLibraryModule)
24 },
25 {
26 path: 'verify-account',
27 loadChildren: () => import('./+signup/+verify-account/verify-account.module').then(m => m.VerifyAccountModule)
28 },
29 {
30 path: 'a',
31 loadChildren: () => import('./+accounts/accounts.module').then(m => m.AccountsModule)
32 },
33 {
34 path: 'c',
35 loadChildren: () => import('./+video-channels/video-channels.module').then(m => m.VideoChannelsModule)
36 },
37 {
38 path: 'about',
39 loadChildren: () => import('./+about/about.module').then(m => m.AboutModule)
40 },
41 {
42 path: 'signup',
43 loadChildren: () => import('./+signup/+register/register.module').then(m => m.RegisterModule)
44 },
45 {
46 path: 'reset-password',
47 loadChildren: () => import('./+reset-password/reset-password.module').then(m => m.ResetPasswordModule)
48 },
49 {
50 path: 'login',
51 loadChildren: () => import('./+login/login.module').then(m => m.LoginModule)
52 },
53 {
54 path: 'search',
55 loadChildren: () => import('./+search/search.module').then(m => m.SearchModule)
56 },
57 {
58 path: 'videos',
59 loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule)
60 },
61 {
62 path: 'remote-interaction',
63 loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule)
64 },
65 {
66 path: 'video-playlists/watch',
67 redirectTo: 'videos/watch/playlist'
68 },
69 {
70 path: 'accounts',
71 redirectTo: 'a'
72 },
73 {
74 path: 'video-channels',
75 redirectTo: 'c'
76 },
77 {
78 matcher: (url): UrlMatchResult => {
79 // Matches /@:actorName
80 if (url.length === 1 && url[0].path.match(/^@[\w]+$/gm)) {
81 return {
82 consumed: url,
83 posParams: {
84 actorName: new UrlSegment(url[0].path.substr(1), {})
85 }
86 }
87 }
88
89 return null
90 },
91 component: RootComponent
92 },
93 {
94 path: '',
95 component: EmptyComponent // Avoid 404, app component will redirect dynamically
96 }
97 ]
98
99 // Avoid 404 when changing language
100 for (const locale of POSSIBLE_LOCALES) {
101 routes.push({
102 path: locale,
103 component: EmptyComponent
104 })
105 }
106
107 routes.push({
108 path: '**',
109 loadChildren: () => import('./+page-not-found/page-not-found.module').then(m => m.PageNotFoundModule)
110 })
111
112 @NgModule({
113 imports: [
114 RouterModule.forRoot(routes, {
115 useHash: Boolean(history.pushState) === false,
116 scrollPositionRestoration: 'disabled',
117 preloadingStrategy: PreloadSelectedModulesList,
118 anchorScrolling: 'disabled'
119 })
120 ],
121 providers: [
122 MenuGuards.guards,
123 PreloadSelectedModulesList,
124 { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
125 ],
126 exports: [ RouterModule ]
127 })
128 export class AppRoutingModule {}