diff options
Diffstat (limited to 'client/src/app/core/routing/homepage-redirect.component.ts')
-rw-r--r-- | client/src/app/core/routing/homepage-redirect.component.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/client/src/app/core/routing/homepage-redirect.component.ts b/client/src/app/core/routing/homepage-redirect.component.ts new file mode 100644 index 000000000..9e3848038 --- /dev/null +++ b/client/src/app/core/routing/homepage-redirect.component.ts | |||
@@ -0,0 +1,30 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { ActivatedRoute } from '@angular/router' | ||
3 | import { is18nPath } from '@shared/core-utils/i18n/i18n' | ||
4 | import { RedirectService } from './redirect.service' | ||
5 | |||
6 | /* | ||
7 | * We have to use a component instead of an homepage because of a weird issue when using router.navigate in guard | ||
8 | * | ||
9 | * Since we also want to use the `skipLocationChange` option, we cannot use a guard that returns a UrlTree | ||
10 | * See https://github.com/angular/angular/issues/27148 | ||
11 | */ | ||
12 | |||
13 | @Component({ | ||
14 | template: '' | ||
15 | }) | ||
16 | export class HomepageRedirectComponent implements OnInit { | ||
17 | |||
18 | constructor ( | ||
19 | private route: ActivatedRoute, | ||
20 | private redirectService: RedirectService | ||
21 | ) { } | ||
22 | |||
23 | ngOnInit () { | ||
24 | const url = this.route.snapshot.url | ||
25 | |||
26 | if (url.length === 0 || is18nPath('/' + url[0])) { | ||
27 | this.redirectService.redirectToHomepage(true) | ||
28 | } | ||
29 | } | ||
30 | } | ||