From 7ffec411ad35016cb14a98b64ab5ca30e17dadbf Mon Sep 17 00:00:00 2001 From: Piet Ostendorp Date: Sun, 26 Oct 2025 00:40:14 +0200 Subject: [PATCH] Redirect first-time visitors to info page Updated routing to use MainPage as the default route and added logic in App component to redirect users to the /info page on their first visit using sessionStorage. --- src/app/app-routing-module.ts | 4 +++- src/app/app.ts | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/app/app-routing-module.ts b/src/app/app-routing-module.ts index c8b47a3..f889ae7 100644 --- a/src/app/app-routing-module.ts +++ b/src/app/app-routing-module.ts @@ -2,9 +2,11 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { PocModelComponent } from './poc-model-component/poc-model-component'; import { HomeComponent } from './home-component/home-component'; +import { MainPage } from './main-page/main-page'; const routes: Routes = [ - { path: '', component: HomeComponent, pathMatch: 'full' }, + { path: '', component: MainPage, pathMatch: 'full' }, + { path: 'info', component: HomeComponent }, { path: 'poc-model', component: PocModelComponent }, { path: '**', component: HomeComponent }, ]; diff --git a/src/app/app.ts b/src/app/app.ts index 15f76bf..90b4e8c 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,4 +1,5 @@ -import { Component, signal } from '@angular/core'; +import { Component, OnInit, signal } from '@angular/core'; +import { Router } from '@angular/router'; @Component({ selector: 'app-root', @@ -6,6 +7,17 @@ import { Component, signal } from '@angular/core'; standalone: false, styleUrl: './app.css', }) -export class App { +export class App implements OnInit{ protected readonly title = signal('infinifront'); + + constructor(private router: Router) {} + + ngOnInit(): void { + const hasVisited = sessionStorage.getItem('hasVisited'); + + if (!hasVisited) { + sessionStorage.setItem('hasVisited', 'true'); + this.router.navigateByUrl('/info', { skipLocationChange: true }); + } + } }