import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

export class AppComponent implements OnInit {

  urlParams = new URLSearchParams(window.location.search);

  constructor(private router: Router) {
  }

  ngOnInit() {
    this.navigate();
  }

  navigate(): void {
    if (this.urlParams.get('post')) {
      this.router.navigate(['/posts'], { queryParams: { post: this.urlParams.get('post') }, skipLocationChange: true });
    } else {
      switch (this.urlParams.get('page')) { // Keeping this style of check in case more pages get added in the future.
        case 'archives':
          this.router.navigate(['/archives'], { skipLocationChange: true });
          break;
        default:
          this.router.navigate(['/'], { skipLocationChange: true });
          break;
      }
    }
  }

}
