1

First of all i tried with this answers but not found my solution: Similar question

Let me expalin how i implemented:

  1. I have two components forgot-password & new-password
  2. When the user submit forgot password form he will get a email verification link.
  3. when user clicks that email link
  4. it will go to forgot-password.ts file and then in ngOnInit ajax call will go.
  5. From ajax response if success data it will redirect to the new-password

or

  1. it will throw the error in frogot password page itself

My issue: when I try to navigate to new-password from forgot-password ts file after ajax response using the external link (Gmail link) ; it appends component data instead of replacing the forgot with new component.

My app.moduel.ts:

import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

@NgModule({
  imports:      [
   BrowserAnimationsModule,
})

And this my route code forgot-password.ts :

if(result.data == "failure")    {
// failure no data
}
else {
// success data
this._router.navigate(['new-password']);
}

NOTE

  1. When I comment these BrowserAnimationsModule in my app.module.ts the routing is working fine.But I need thisBrowserAnimationsModule.! what is the alternate solution.
  2. If not form external link(Gmail) the routing is working fine.
Mr world wide
  • 4,696
  • 7
  • 43
  • 97
  • can u pls post ur routing file and the ajax call from where u route to `new-password` page – Dhyey Dec 28 '17 at 05:02
  • 1
    Did you find a solution to the problem? I'm trying to fix this issue in my app for about two weeks with no luck – vanelizarov Jan 22 '18 at 11:39
  • Yes.!! when there is an error in your component `A` or `B` this issue is coming..! Luckily my error displayed in the `console` which is `touched undefined ` so I found alternate to that error(fixed error). try to find the error in both `typescript` files you will find the solution.ATB – Mr world wide Jan 22 '18 at 12:06

3 Answers3

4

Update to lastest version of Angular

Also, try :

 if(result.data == "failure")    {
    // failure no data
 }
 else {
   // success data
   this.zone.run(() =>{
      this._router.navigate(['new-password']);
   });
 }
isy
  • 531
  • 1
  • 12
  • 27
  • I have already tried with `zone` and `set time`, but it's not working, anyway, i found the solution I will update my answer soon. – Mr world wide Dec 29 '17 at 04:35
  • 1
    Using 'zone' worked more me in angular 6. Can someone point me the relation between BrowserAnimationModule and zone. I've found this: https://github.com/angular/angular/issues/19093 but clueless. – Krishna Mohan Jun 23 '18 at 11:04
1

For me

setTimeout(() => {
   this.router.navigate(['']);
}, 0);

did the trick

zmag
  • 7,825
  • 12
  • 32
  • 42
0

Instead of navigating to new-password from forgot-password ts file,you can give the route link of your new password page in your email verification link,and in constructor of new password component you can use your ajax call,on success of that open new password page and in error case navigate to the error page.

Abhishek saini
  • 507
  • 1
  • 8
  • 29
  • The `new-password` page holds very sensitive data until unless the email link is true then only it should go.! `else` it should stop @forgot. `Secondly like you said` if I check code new new-password page on failure it should redirect to @forgot hence both are same; issue cant fix with that – Mr world wide Dec 28 '17 at 05:15
  • You can use *ngif in the same new password page ,and in the error case redirect to the error page. – Abhishek saini Dec 28 '17 at 05:20
  • there is no error page...!!!!!! i think you will not understand my point – Mr world wide Dec 28 '17 at 05:21