Redirect page after login

Asked

Viewed 112 times

0

I’m trying to redirect to the homepage after logging in, but the system won’t log in

Test code I made for demonstration is this:

ngOnInit() {
    this.loginForm = new FormGroup({
      login:    new FormControl('', {validators: [Validators.required], 'updateOn': 'blur'}),
      password: new FormControl('', {validators: [Validators.required]})
    }, );
    this.navigateTo = this.activedRoute.snapshot.params['to'] || '/estacao';
  }
  login() {
     this.router.navigate(['/pagina'])
  }

This is the button code

<button type="submit" class="btn btn-primary btn-block" [disabled]="loginForm.invalid" (click)

Follow an example in stackblits: here and here

Archive with the routes:

export const ROUTES: Routes = [
  {path: '', component: LoginComponent},
  {path: ':to', component: LoginComponent},
  {
    path: 'pagina',
    component: SistemaComponent, // Layout diferente da página de login
    children: [
      {path: '', component: PaginaComponent}
    ]
  }
 ]

1 answer

1


{
    path: 'pagina',
    component: SistemaComponent, // Layout diferente da página de login
    children: [
      {path: '', component: PaginaComponent}
    ]
  }, 
{path: '', component: LoginComponent},
{path: ':to', component: LoginComponent}

Routes are chosen in order, and in your case you were always redirecting to login. Order matters a lot for routes to work properly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.