Advertisement
Guest User

app.component.ts

a guest
Feb 6th, 2024
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { UserAuthService } from './services/auth/user-auth.service';
  4. import { Location } from '@angular/common';
  5. import { GlobalService } from './services/global.service';
  6. @Component({
  7. selector: 'app-root',
  8. templateUrl: './app.component.html',
  9. styleUrls: ['./app.component.scss'],
  10. // standalone:true,
  11. })
  12. export class AppComponent implements OnInit {
  13. title = 'Drennen Dooms';
  14.  
  15. constructor(
  16. private router: Router,
  17. private userAuth: UserAuthService,
  18. private globalService: GlobalService,
  19. private location: Location,
  20. ) {
  21. // router.navigate(['work']);
  22. }
  23. ngOnInit(): void {
  24. console.log(`path: ${this.location.path()}`);
  25.  
  26. if (this.location.path().replaceAll('/', '') == 'logout') {
  27. this.userAuth.logout();
  28. this.globalService.setRoute('home');
  29. }
  30.  
  31. if (
  32. (this.location.path() === '/' ||
  33. this.location.path() == '' ||
  34. this.location.path() == undefined) &&
  35. (this.globalService.routeSubject.getValue() == undefined ||
  36. this.globalService.routeSubject.getValue() == '')
  37. ) {
  38. console.log('routing', this.globalService.routeSubject.getValue());
  39. this.globalService.setRoute('home');
  40. } else {
  41. if (this.location.path() == '') {
  42. this.globalService.setRoute('home');
  43. } else {
  44. console.log(`routing to ${this.location.path()}`);
  45. this.globalService.setRoute(this.location.path().replaceAll('/', ''));
  46. }
  47. }
  48.  
  49. this.globalService.routeSubject.subscribe((route) => {
  50. this.router.navigate([route]);
  51. console.log('from', this.router.url, 'to', route);
  52. });
  53.  
  54. // _route.queryParams.subscribe((params) => {console.log(`route params\n${params}`)});
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement