Route Reuse Strategy , Route Children's not firing shouldReuseRoute method?

1.6k Views Asked by At

i have declared routes like below

const routes: Routes = [
    {
        path: '',
        component: NgxMindxRunComponent,
        data: {
            reuse: true
        },
        children: [
            {
                path: '',
                component: NgxMindxRunDiagramComponent,
                data: {
                    reuse: true
                }

            },
            {
                path: 'load/:id',
                component: NgxMindxRunDiagramComponent,
                data: {
                    reuse: true
                }
                
            },
            {
                path: 'file/:fileName',
                component: NgxMindxRunDiagramComponent,
                data: {
                    reuse: true
                },
                
            }],
            
    }
];

and the issue is when current route is : http://localhost:4200/run/ then i navigate to "http://localhost:4200/run/file/1" every thing is OK! but when i navigate from "http://localhost:4200/run/file/1" to the "http://localhost:4200/run/file/2" the shouldReuseRoute method is not firing then cant store component!! there is same issue for "http://localhost:4200/run/load/..." it means i'm trying to call store method on RouteReuseStrategy class which i provided in app.module , but i cant reach i tried to find same question but i didn't find anything my other question is , is it OK i used same component with different path , is it make issue in route reuse Strategy usage?

1

There are 1 best solutions below

3
Charlie V On

I've encountered the same problem in the past, I've solved this with the following addition in the component:

  constructor(private route: ActivatedRoute,
              private router: Router) {
    this.router.routeReuseStrategy.shouldReuseRoute = function () {
      return false
    }
  }


  ngOnInit(){
     this.route.params.subscribe(...) // your code for handling route
  }