Create RedirectComponent to handle dynamic redirections and update routes for improved maintainability.

This commit is contained in:
akastijn 2025-11-13 21:10:38 +01:00
parent 42786dce74
commit 19bc6fc8e3
4 changed files with 52 additions and 1 deletions

View File

@ -4,9 +4,13 @@ import {AuthGuard} from './guards/auth.guard';
export const routes: Routes = [
{
path: 'worlddl',
redirectTo: 'https://www.mediafire.com/folder/zblzjurjleq6i/Altitude_servers_1.17.1',
redirectTo: 'redirect/worlddl',
pathMatch: 'full'
},
{
path: 'redirect/:type',
loadComponent: () => import('./shared-components/redirect/redirect.component').then(m => m.RedirectComponent),
},
{
path: 'login/:code',
loadComponent: () => import('./pages/home/home.component').then(m => m.HomeComponent),

View File

@ -0,0 +1,3 @@
<div class="redirect-loading">
Redirecting...
</div>

View File

@ -0,0 +1,8 @@
.redirect-loading {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
font-family: system-ui, -apple-system, "Segoe UI", Roboto;
color: #555;
}

View File

@ -0,0 +1,36 @@
import {Component, inject, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
@Component({
selector: 'app-redirect',
imports: [],
templateUrl: './redirect.component.html',
styleUrl: './redirect.component.scss'
})
export class RedirectComponent implements OnInit {
private router: Router = inject(Router)
private route: ActivatedRoute = inject(ActivatedRoute)
private map: Record<string, string> = {
'worlddl': 'https://www.mediafire.com/folder/zblzjurjleq6i/Altitude_servers_1.17.1',
};
private getRedirectTarget(key: string): string | null {
const value = this.map[key];
return value ?? null;
}
ngOnInit(): void {
const type = this.route.snapshot.paramMap.get('type');
if (type) {
const target = this.getRedirectTarget(type);
if (target) {
this.router.navigateByUrl(target).then();
} else {
this.router.navigate(['/']).then();
}
} else {
this.router.navigate(['/']).then();
}
}
}