Created
July 31, 2025 12:38
-
-
Save miladj3/fba4027b1e386b968e7638f2f2fac38a to your computer and use it in GitHub Desktop.
new redirect to routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Routes } from '@angular/router'; | |
import { inject, Injectable, signal } from '@angular/core'; | |
export const routes: Routes = [ | |
// π Authentication-Based Redirect | |
{ | |
path: '', | |
redirectTo: () => (inject(AuthService).isAuth() ? 'dashboard' : 'login'), | |
}, | |
// π Language-Specific Redirect (based on browser/lang preference) | |
{ | |
path: 'home', | |
redirectTo: () => { | |
const lang = | |
localStorage.getItem('lang') || navigator.language.slice(0, 2) || 'en'; | |
return `home/${lang.toLowerCase()}`; // home/ru || home/en ... | |
}, | |
}, | |
// π³ Payment Result Handler (based on status from URL query params) | |
{ | |
path: 'payment', | |
redirectTo: (route) => | |
route.queryParams['status'] === 'success' ? 'thank-you' : 'checkout', | |
}, | |
]; | |
@Injectable({ providedIn: 'root' }) | |
export class AuthService { | |
isAuth = signal(true); | |
} | |
console.log(routes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment