Angular Route Start and Route End Events

前端 未结 1 589
孤独总比滥情好
孤独总比滥情好 2021-01-14 04:39

How can i get access to the routing start and routing end events? I want to show a Progress Bar while routing and loading data.

Can someone tell me how this works?

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-14 05:07

    If you prefer to work with an observable:

    import { Router, NavigationStart } from '@angular/router';
    ...
        constructor(router:Router) {
          router.events.subscribe(e => {
            if(e instanceof NavigationStart) {
              // Init Code
            }
    
            if(e instanceof NavigationEnd) {
              // Exit Code
            }
          }
        });
    

    0 讨论(0)
提交回复
热议问题