arch(sprint1): resolve dynamic pages by route config

This commit is contained in:
sdarbinyan
2026-07-03 02:04:01 +04:00
parent ac48799d9a
commit d6a1d5e3f5
4 changed files with 59 additions and 9 deletions

View File

@@ -0,0 +1,49 @@
import { Injectable } from '@angular/core';
import { map, Observable } from 'rxjs';
import { ConfigService } from '../../core/config/config.service';
import { PageConfig } from '../../shared/models/config';
@Injectable({ providedIn: 'root' })
export class PageResolverService {
constructor(private readonly configService: ConfigService) {}
resolveByUrl(url: string): Observable<PageConfig | null> {
const pagePath = this.toPagePath(url);
return this.configService.loadBootstrap().pipe(
map((bootstrap) => {
return (
bootstrap.pages.find((page) => {
if (page.visible === false) {
return false;
}
return this.normalizePath(page.route.path) === pagePath;
}) ?? null
);
})
);
}
private toPagePath(url: string): string {
const noHash = url.split('#')[0];
const noQuery = noHash.split('?')[0];
const segments = noQuery.split('/').filter(Boolean);
const withoutLang = segments.length > 0 ? segments.slice(1) : [];
if (withoutLang.length === 0) {
return '/';
}
return this.normalizePath(`/${withoutLang.join('/')}`);
}
private normalizePath(path: string): string {
const trimmed = path.trim();
if (!trimmed || trimmed === '/') {
return '/';
}
return `/${trimmed.replace(/^\/+/, '').replace(/\/+$/, '')}`;
}
}