X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Frouting%2Fcustom-reuse-strategy.ts;h=269b9d193ae6557fea70680ddbd014c1ce861479;hb=ca0f030787a6334609aa1b0c7cea44676adf3632;hp=c0f9f04e02605aa91db18f23f23436fff9c998c5;hpb=610d0be13b3d01f653ef269271dd667a57c85ef2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/routing/custom-reuse-strategy.ts b/client/src/app/core/routing/custom-reuse-strategy.ts index c0f9f04e0..269b9d193 100644 --- a/client/src/app/core/routing/custom-reuse-strategy.ts +++ b/client/src/app/core/routing/custom-reuse-strategy.ts @@ -1,5 +1,8 @@ +import { ComponentRef, Injectable } from '@angular/core' import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router' -import { Injectable } from '@angular/core' +import { logger } from '@root-helpers/logger' +import { DisableForReuseHook } from './disable-for-reuse-hook' +import { PeerTubeRouterService, RouterSetting } from './peertube-router.service' @Injectable() export class CustomReuseStrategy implements RouteReuseStrategy { @@ -20,9 +23,11 @@ export class CustomReuseStrategy implements RouteReuseStrategy { const key = this.generateKey(route) this.recentlyUsed = key - console.log('Storing component %s to reuse later.', key); + logger.info(`Storing component ${key} to reuse later.`) - (handle as any).componentRef.instance.disableForReuse() + const componentRef = (handle as any).componentRef as ComponentRef + componentRef.instance.disableForReuse() + componentRef.changeDetectorRef.detectChanges() this.storedRouteHandles.set(key, handle) @@ -42,7 +47,7 @@ export class CustomReuseStrategy implements RouteReuseStrategy { const key = this.generateKey(route) this.recentlyUsed = key - console.log('Reusing component %s.', key) + logger.info(`Reusing component ${key}.`) const handle = this.storedRouteHandles.get(key) if (!handle) return handle; @@ -54,7 +59,7 @@ export class CustomReuseStrategy implements RouteReuseStrategy { // Reuse the route if we're going to and from the same route shouldReuseRoute (future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean { - return future.routeConfig === curr.routeConfig + return future.routeConfig === curr.routeConfig && future.routeConfig?.data?.reloadOnSameNavigation !== true } private gb () { @@ -62,7 +67,7 @@ export class CustomReuseStrategy implements RouteReuseStrategy { this.storedRouteHandles.forEach((r, key) => { if (key === this.recentlyUsed) return - console.log('Removing stored component %s.', key); + logger.info(`Removing stored component ${key}`); (r as any).componentRef.destroy() this.storedRouteHandles.delete(key) @@ -78,6 +83,8 @@ export class CustomReuseStrategy implements RouteReuseStrategy { } private isReuseEnabled (route: ActivatedRouteSnapshot) { - return route.data.reuse && route.data.reuse.enabled && route.queryParams[ 'a-state' ] + // Cannot use peertube router here because of cyclic router dependency + return route.data.reuse?.enabled && + !!(route.queryParams[PeerTubeRouterService.ROUTE_SETTING_NAME] & RouterSetting.REUSE_COMPONENT) } }