Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submitting a connected form causes an extra navigation #34

Open
karmasakshi opened this issue Jan 3, 2025 · 1 comment
Open

Submitting a connected form causes an extra navigation #34

karmasakshi opened this issue Jan 3, 2025 · 1 comment

Comments

@karmasakshi
Copy link

karmasakshi commented Jan 3, 2025

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

  1. Create a reactive form and connect it with this._bindQueryParamsManager
  2. Add a (submit) function
  3. Route to a different path /xyz in the submit function using this._router.navigateByUrl('/xyz')
  4. Submit form

Navigation doesn't happen (gets cancelled).

Expected behavior

Router should navigate to /xyz. On debugging with withDebugTracing(), the code noticed is 1, which is SupersededByNewNavigation. On calling this._bindQueryParamsManager.destroy() in the submit function, navigation happens as expected.

Minimal reproduction of the problem with instructions

export class SignInPageComponent implements OnInit, OnDestroy {
  private readonly _bindQueryParamsFactory = inject(BindQueryParamsFactory);

  private readonly _bindQueryParamsManager: BindQueryParamsManager<{
    email: string;
  }>;

  public readonly signInFormGroup: FormGroup<{
    email: FormControl<string | null>;
    password: FormControl<string | null>;
  }>;

 public constructor() {
    this._bindQueryParamsManager = this._bindQueryParamsFactory.create([
      { queryKey: 'email', type: 'string' },
    ]);

    this.signInFormGroup = this._formBuilder.group({
      email: ['', [Validators.required, Validators.email]],
      password: ['', [Validators.required]],
    });
}

  public ngOnInit(): void {
    this._bindQueryParamsManager.connect(this.signInFormGroup);
  }

  public ngOnDestroy(): void {
    this._bindQueryParamsManager.destroy();
  }

  public signInWithPassword(email: string, password: string): void {
    // this._bindQueryParamsManager.destroy(); <-- Without this, navigation gets cancelled
    void this._router.navigateByUrl('/xyz');
  }
}

What is the motivation / use case for changing the behavior?

Environment


Angular version: 19.0.5


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [X] Firefox version 133
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 22  
- Platform:  Windows  

Others:

@karmasakshi karmasakshi changed the title Submitting a linked form causes an extra navigation Submitting a connected form causes an extra navigation Jan 3, 2025
@karmasakshi
Copy link
Author

On further investigation, it's probably because enabling/disabling the form fires a navigation event when connected to this._bindQueryParamsManager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant