2017-01-17 9 views
5

मेरे पास एक कोणीय 2 एप्लिकेशन है, और रूट इवेंट्स को रोकना, उन्हें होने से रोकना, एनीमेशन खेलना और फिर रूट करना जारी रखना है। अगर मैं एक वर्गएंगुलर 2 इंटरसेप्टिंग रूट इवेंट्स और फिर

export class SomeComponent { 
    constructor(private router: Router){ 
     router.events.subscribe(evt => { 
      if(evt instanceof NavigationStart){ 
       //I would like to cancel the event here the first time, and then 
       //play an animation, after the animation is done, trigger the router 
       //to go to the original route it wanted to. 
      } 
     }) 
    } 
} 

वहाँ नेविगेशन प्रक्रिया परिष्करण से कि रूटर को रोकने के लिए एक रास्ता है है

मेरे विचार इस

कर रहे हैं?

+0

क्या आप यूआरएल में 'शोएनीमेशन' जैसे कुछ जोड़ सकते हैं और हर बार यूआरएल परिवर्तन होता है, यह जांचता है कि वह ध्वज वहां है, और यदि ऐसा है, तो मूल मार्ग के पते पर जाने से पहले एक एनीमेशन करता है? – Pytth

उत्तर

8

आप पैरेंट रूट के लिए CanActivate गार्ड बना सकते हैं, जहां आप कुछ ग्लोबल वैरिएबल के आधार पर नेविगेशन को रोक सकते हैं, तो वैरिएबल के आधार पर वैल्यू हो सकता है कि एनीमेशन दिखाया गया है या नहीं।

तो क्या आप ऐसा कर सकते हैं है,

export class AnimationGuard implements CanActivate { 
    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { 
    if(HasAnimationRun){ 
     return true; 
    } 
    runAnimation(state.url); 
    return false; 
    } 
} 

runAnimation(url){ 
    // run animation 
    // set global variable. 
    // navigate to url 
} 

CanActivate here बारे में अधिक पढ़ें।

उम्मीद है कि इससे मदद मिलती है !!