]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/routing/custom-reuse-strategy.ts
Add error info on router error
[github/Chocobozzz/PeerTube.git] / client / src / app / core / routing / custom-reuse-strategy.ts
index 3000093a8df8f737d57342a7517b440cd02d922e..269b9d193ae6557fea70680ddbd014c1ce861479 100644 (file)
@@ -1,7 +1,8 @@
-import { Injectable } from '@angular/core'
+import { ComponentRef, Injectable } from '@angular/core'
 import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router'
-import { RouterSetting } from './'
-import { PeerTubeRouterService } from './peertube-router.service'
+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 {
@@ -22,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<DisableForReuseHook>
+    componentRef.instance.disableForReuse()
+    componentRef.changeDetectorRef.detectChanges()
 
     this.storedRouteHandles.set(key, handle)
 
@@ -44,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;
@@ -56,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 () {
@@ -64,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)