PeerTube/client/src/app/app-routing.module.ts

218 lines
5.9 KiB
TypeScript
Raw Normal View History

import { NgModule } from '@angular/core'
import { RouteReuseStrategy, RouterModule, Routes, UrlMatchResult, UrlSegment } from '@angular/router'
2019-03-21 16:49:46 +01:00
import { CustomReuseStrategy } from '@app/core/routing/custom-reuse-strategy'
import { MenuGuards } from '@app/core/routing/menu-guard.service'
import { POSSIBLE_LOCALES } from '@peertube/peertube-core-utils'
2021-06-04 14:39:47 +02:00
import { HomepageRedirectComponent, MetaGuard, PreloadSelectedModulesList } from './core'
2020-06-23 14:49:20 +02:00
import { EmptyComponent } from './empty.component'
import { USER_USERNAME_REGEX_CHARACTERS } from './shared/form-validators/user-validators'
import { ActorRedirectGuard } from './shared/shared-main'
2016-11-20 17:18:15 +01:00
const routes: Routes = [
2018-05-17 15:25:50 +02:00
{
path: 'admin',
canActivate: [ MenuGuards.close() ],
canDeactivate: [ MenuGuards.open() ],
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+admin/admin.module').then(m => m.AdminModule),
canActivateChild: [ MetaGuard ]
2018-05-17 15:25:50 +02:00
},
{
path: 'home',
loadChildren: () => import('./+home/home.module').then(m => m.HomeModule),
canActivateChild: [ MetaGuard ]
2018-05-17 15:25:50 +02:00
},
{
path: 'my-account',
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+my-account/my-account.module').then(m => m.MyAccountModule),
canActivateChild: [ MetaGuard ]
2018-05-17 15:25:50 +02:00
},
{
path: 'my-library',
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+my-library/my-library.module').then(m => m.MyLibraryModule),
canActivateChild: [ MetaGuard ]
},
{
path: 'verify-account',
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+signup/+verify-account/verify-account.module').then(m => m.VerifyAccountModule),
canActivateChild: [ MetaGuard ]
},
{
path: 'accounts',
redirectTo: 'a'
},
2018-05-17 15:25:50 +02:00
{
path: 'a',
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+accounts/accounts.module').then(m => m.AccountsModule),
canActivateChild: [ MetaGuard ]
2018-05-17 15:25:50 +02:00
},
{
path: 'video-channels',
redirectTo: 'c'
},
2018-05-17 15:25:50 +02:00
{
path: 'c',
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+video-channels/video-channels.module').then(m => m.VideoChannelsModule),
canActivateChild: [ MetaGuard ]
2018-05-31 11:35:01 +02:00
},
{
path: 'manage',
loadChildren: () => import('./+manage/manage.module').then(m => m.ManageModule),
canActivateChild: [ MetaGuard ]
},
{
path: 'p',
loadChildren: () => import('./+plugin-pages/plugin-pages.module').then(m => m.PluginPagesModule),
canActivateChild: [ MetaGuard ]
},
2018-06-27 14:21:03 +02:00
{
path: 'about',
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+about/about.module').then(m => m.AboutModule),
canActivateChild: [ MetaGuard ]
2018-06-27 14:21:03 +02:00
},
2019-05-29 14:39:49 +02:00
{
path: 'signup',
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+signup/+register/register.module').then(m => m.RegisterModule),
canActivateChild: [ MetaGuard ]
2019-05-29 14:39:49 +02:00
},
2020-06-23 14:49:20 +02:00
{
path: 'reset-password',
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+reset-password/reset-password.module').then(m => m.ResetPasswordModule),
canActivateChild: [ MetaGuard ]
2020-06-23 14:49:20 +02:00
},
{
path: 'login',
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+login/login.module').then(m => m.LoginModule),
canActivateChild: [ MetaGuard ]
2020-06-23 14:49:20 +02:00
},
{
path: 'search',
2021-05-14 16:12:45 +02:00
loadChildren: () => import('./+search/search.module').then(m => m.SearchModule),
canActivateChild: [ MetaGuard ]
2020-06-23 14:49:20 +02:00
},
2020-06-23 14:49:20 +02:00
{
path: 'videos/upload',
loadChildren: () => import('@app/+videos/+video-edit/video-add.module').then(m => m.VideoAddModule),
canActivateChild: [ MetaGuard ],
data: {
meta: {
title: $localize`Upload a video`
}
}
2020-06-23 14:49:20 +02:00
},
2021-01-14 14:13:23 +01:00
{
path: 'videos/update/:uuid',
loadChildren: () => import('@app/+videos/+video-edit/video-update.module').then(m => m.VideoUpdateModule),
canActivateChild: [ MetaGuard ],
data: {
meta: {
title: $localize`Edit a video`
}
}
},
{
path: 'videos/watch/playlist',
redirectTo: 'w/p'
},
{
path: 'videos/watch',
redirectTo: 'w'
},
{
path: 'w',
loadChildren: () => import('@app/+videos/+video-watch/video-watch.module').then(m => m.VideoWatchModule),
data: {
2021-06-04 11:46:17 +02:00
preload: 5000
}
},
{
path: 'videos',
loadChildren: () => import('./+videos/videos.module').then(m => m.VideosModule),
2021-05-14 16:12:45 +02:00
canActivateChild: [ MetaGuard ]
2021-01-14 14:13:23 +01:00
},
2021-03-04 09:04:10 +01:00
{
path: 'video-playlists/watch',
redirectTo: 'videos/watch/playlist'
},
{
path: 'remote-interaction',
loadChildren: () => import('./+remote-interaction/remote-interaction.module').then(m => m.RemoteInteractionModule),
canActivateChild: [ MetaGuard ]
},
2022-02-11 10:51:33 +01:00
{
2022-03-22 16:58:49 +01:00
path: 'studio',
loadChildren: () => import('./+video-studio/video-studio.module').then(m => m.VideoStudioModule),
2022-02-11 10:51:33 +01:00
canActivateChild: [ MetaGuard ]
},
2022-04-05 14:03:52 +02:00
{
path: 'stats',
loadChildren: () => import('./+stats/stats.module').then(m => m.StatsModule),
canActivateChild: [ MetaGuard ]
},
// Matches /@:actorName
{
matcher: (url): UrlMatchResult => {
const regex = new RegExp(`^@(${USER_USERNAME_REGEX_CHARACTERS}+)$`)
if (url.length !== 1) return null
const matchResult = url[0].path.match(regex)
if (!matchResult) return null
return {
consumed: url,
posParams: {
actorName: new UrlSegment(matchResult[1], {})
}
}
},
pathMatch: 'full',
canActivate: [ ActorRedirectGuard ],
component: EmptyComponent
},
2018-06-28 17:16:22 +02:00
{
path: '',
2021-06-04 14:39:47 +02:00
component: HomepageRedirectComponent
2018-05-17 15:25:50 +02:00
}
]
2016-11-20 17:18:15 +01:00
2020-08-26 08:54:19 +02:00
// Avoid 404 when changing language
for (const locale of POSSIBLE_LOCALES) {
routes.push({
path: locale,
2021-06-04 14:39:47 +02:00
component: HomepageRedirectComponent
2020-08-26 08:54:19 +02:00
})
}
routes.push({
path: '**',
2022-07-08 10:32:33 +02:00
loadChildren: () => import('./+error-page/error-page.module').then(m => m.ErrorPageModule)
2020-08-26 08:54:19 +02:00
})
2016-11-20 17:18:15 +01:00
@NgModule({
2017-09-06 21:48:15 +02:00
imports: [
RouterModule.forRoot(routes, {
2024-02-22 10:12:04 +01:00
useHash: false,
// Redefined in app component
2019-03-21 16:49:46 +01:00
scrollPositionRestoration: 'disabled',
preloadingStrategy: PreloadSelectedModulesList,
2019-03-21 16:49:46 +01:00
anchorScrolling: 'disabled'
2017-09-06 21:48:15 +02:00
})
],
2018-03-01 13:57:29 +01:00
providers: [
MenuGuards.guards,
2019-03-21 16:49:46 +01:00
PreloadSelectedModulesList,
{ provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
2018-03-01 13:57:29 +01:00
],
2016-11-20 17:18:15 +01:00
exports: [ RouterModule ]
})
export class AppRoutingModule {}