homepage-redirect.component.ts 869 B

123456789101112131415161718192021222324252627282930
  1. import { Component, OnInit } from '@angular/core'
  2. import { ActivatedRoute } from '@angular/router'
  3. import { is18nPath } from '@peertube/peertube-core-utils'
  4. import { RedirectService } from './redirect.service'
  5. /*
  6. * We have to use a component instead of an homepage because of a weird issue when using router.navigate in guard
  7. *
  8. * Since we also want to use the `skipLocationChange` option, we cannot use a guard that returns a UrlTree
  9. * See https://github.com/angular/angular/issues/27148
  10. */
  11. @Component({
  12. template: ''
  13. })
  14. export class HomepageRedirectComponent implements OnInit {
  15. constructor (
  16. private route: ActivatedRoute,
  17. private redirectService: RedirectService
  18. ) { }
  19. ngOnInit () {
  20. const url = this.route.snapshot.url
  21. if (url.length === 0 || is18nPath('/' + url[0])) {
  22. this.redirectService.redirectToHomepage(true)
  23. }
  24. }
  25. }