From fc21ef5c62d845576a916414468b3a57370a57b2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 4 Jun 2021 14:39:47 +0200 Subject: Speed up plugins loading --- .../core/routing/homepage-redirect.component.ts | 30 ++++++++++++++++++++++ client/src/app/core/routing/index.ts | 1 + client/src/app/core/routing/redirect.service.ts | 1 - 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 client/src/app/core/routing/homepage-redirect.component.ts (limited to 'client/src/app/core/routing') 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 @@ +import { Component, OnInit } from '@angular/core' +import { ActivatedRoute } from '@angular/router' +import { is18nPath } from '@shared/core-utils/i18n/i18n' +import { RedirectService } from './redirect.service' + +/* + * We have to use a component instead of an homepage because of a weird issue when using router.navigate in guard + * + * Since we also want to use the `skipLocationChange` option, we cannot use a guard that returns a UrlTree + * See https://github.com/angular/angular/issues/27148 +*/ + +@Component({ + template: '' +}) +export class HomepageRedirectComponent implements OnInit { + + constructor ( + private route: ActivatedRoute, + private redirectService: RedirectService + ) { } + + ngOnInit () { + const url = this.route.snapshot.url + + if (url.length === 0 || is18nPath('/' + url[0])) { + this.redirectService.redirectToHomepage(true) + } + } +} diff --git a/client/src/app/core/routing/index.ts b/client/src/app/core/routing/index.ts index 4314ea475..d0c688a2f 100644 --- a/client/src/app/core/routing/index.ts +++ b/client/src/app/core/routing/index.ts @@ -1,6 +1,7 @@ export * from './can-deactivate-guard.service' export * from './custom-reuse-strategy' export * from './disable-for-reuse-hook' +export * from './homepage-redirect.component' export * from './login-guard.service' export * from './menu-guard.service' export * from './meta-guard.service' diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts index 198332b00..17d9d1358 100644 --- a/client/src/app/core/routing/redirect.service.ts +++ b/client/src/app/core/routing/redirect.service.ts @@ -42,7 +42,6 @@ export class RedirectService { return this.defaultRoute } - getDefaultTrendingAlgorithm () { return this.defaultTrendingAlgorithm } -- cgit v1.2.3