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.
This commit is contained in:
@@ -2,9 +2,11 @@ import { NgModule } from '@angular/core';
|
|||||||
import { RouterModule, Routes } from '@angular/router';
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
import { PocModelComponent } from './poc-model-component/poc-model-component';
|
import { PocModelComponent } from './poc-model-component/poc-model-component';
|
||||||
import { HomeComponent } from './home-component/home-component';
|
import { HomeComponent } from './home-component/home-component';
|
||||||
|
import { MainPage } from './main-page/main-page';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: '', component: HomeComponent, pathMatch: 'full' },
|
{ path: '', component: MainPage, pathMatch: 'full' },
|
||||||
|
{ path: 'info', component: HomeComponent },
|
||||||
{ path: 'poc-model', component: PocModelComponent },
|
{ path: 'poc-model', component: PocModelComponent },
|
||||||
{ path: '**', component: HomeComponent },
|
{ path: '**', component: HomeComponent },
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Component, signal } from '@angular/core';
|
import { Component, OnInit, signal } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@@ -6,6 +7,17 @@ import { Component, signal } from '@angular/core';
|
|||||||
standalone: false,
|
standalone: false,
|
||||||
styleUrl: './app.css',
|
styleUrl: './app.css',
|
||||||
})
|
})
|
||||||
export class App {
|
export class App implements OnInit{
|
||||||
protected readonly title = signal('infinifront');
|
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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user