1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00
pigallery2/frontend/app/app.routing.ts

73 lines
2.0 KiB
TypeScript
Raw Normal View History

2018-03-30 15:30:30 -04:00
import {ModuleWithProviders} from '@angular/core';
import {RouterModule, Routes, UrlMatchResult, UrlSegment} from '@angular/router';
import {LoginComponent} from './ui/login/login.component';
import {GalleryComponent} from './ui/gallery/gallery.component';
import {AdminComponent} from './ui/admin/admin.component';
import {ShareLoginComponent} from './ui/sharelogin/share-login.component';
2018-11-30 15:36:42 +01:00
import {QueryParams} from '../../common/QueryParams';
import {DuplicateComponent} from './ui/duplicates/duplicates.component';
import {FacesComponent} from './ui/faces/faces.component';
2016-12-26 23:36:38 +01:00
export function galleryMatcherFunction(
segments: UrlSegment[]): UrlMatchResult | null {
if (segments.length === 0) {
return null;
}
const path = segments[0].path;
const posParams: { [key: string]: UrlSegment } = {};
if (path === 'gallery') {
if (segments.length > 1) {
posParams[QueryParams.gallery.directory] = segments[1];
}
return {consumed: segments.slice(0, Math.min(segments.length, 2)), posParams};
}
if (path === 'search') {
if (segments.length > 1) {
posParams[QueryParams.gallery.searchText] = segments[1];
}
return {consumed: segments.slice(0, Math.min(segments.length, 2)), posParams};
}
if (path === 'share') {
if (segments.length > 1) {
posParams[QueryParams.gallery.sharingKey_long] = segments[1];
}
return {consumed: segments.slice(0, Math.min(segments.length, 2)), posParams};
}
return null;
}
2016-12-26 23:36:38 +01:00
const ROUTES: Routes = [
{
path: 'login',
component: LoginComponent
},
2017-07-03 19:17:49 +02:00
{
path: 'shareLogin',
component: ShareLoginComponent
},
{
path: 'admin',
component: AdminComponent
},
2019-01-18 00:26:20 +01:00
{
path: 'duplicates',
component: DuplicateComponent
},
2019-02-14 18:25:55 -05:00
{
path: 'faces',
component: FacesComponent
},
{
matcher: galleryMatcherFunction,
2017-07-03 19:17:49 +02:00
component: GalleryComponent
},
2017-07-20 21:06:48 +02:00
{path: '', redirectTo: '/login', pathMatch: 'full'},
{path: '**', redirectTo: '/login', pathMatch: 'full'}
2016-12-26 23:36:38 +01:00
];
export const appRoutes: ModuleWithProviders = RouterModule.forRoot(ROUTES);