Can't reload/refresh active route

前端 未结 10 1831
遇见更好的自我
遇见更好的自我 2020-11-30 08:19

I have recently updated to the new RC3 and Router3alpha and it seems some things have changed.

I noticed that a click on the link of an active route does no longer r

10条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 09:12

    If you really need to trick the Router into reloading the component on each routerLink click, you can use the following code in your Component

    constructor(private router: Router){
     // override the route reuse strategy
     this.router.routeReuseStrategy.shouldReuseRoute = function(){
        return false;
     }
    
     this.router.events.subscribe((evt) => {
        if (evt instanceof NavigationEnd) {
           // trick the Router into believing it's last link wasn't previously loaded
           this.router.navigated = false;
           // if you need to scroll back to top, here is the right place
           window.scrollTo(0, 0);
        }
    });
    
    }
    

    Hope this helps

提交回复
热议问题