Redirect page after login

0

I'm trying to redirect to the home page after logging in, but the system does not log out

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)

Here's an example in stackblits: here and here

File with 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}
    ]
  }
 ]
    
asked by anonymous 12.09.2018 / 17:34

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}

The routes are chosen in order, and in your case was always redirecting to the login. Order matters a lot for the routes to work properly.

    
12.09.2018 / 19:10