Skip to content

Instantly share code, notes, and snippets.

@miladj3
Created July 31, 2025 12:38
Show Gist options
  • Save miladj3/fba4027b1e386b968e7638f2f2fac38a to your computer and use it in GitHub Desktop.
Save miladj3/fba4027b1e386b968e7638f2f2fac38a to your computer and use it in GitHub Desktop.
new redirect to routes
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