I want to navigate to another page after I click "Login"

Discussão em 'Angular' iniciado por owwoj, Março 10, 2025.

  1. owwoj

    owwoj Guest

    I use .NET as back-end and now I'm working with Angular for routing part. I'm stuck in navigate to another page using authentication. I am supposed to use navigate router after subscribe, but I don't know how

    export class LoginComponent {

    title = 'webUI.UI';
    user = new User();

    constructor(private authService: AuthService, private router: Router) {}

    login(user: User) {
    this.authService.login(user).subscribe((token: string) => {
    localStorage.setItem('authToken', token);
    });

    if (localStorage.getItem('authToken') != null) {
    ??????

    }
    }
    }


    My router:

    const routes: Routes = [

    {
    path: 'login',
    component: LoginComponent
    },

    {
    path: 'signup',
    component: SignupComponent
    },

    {
    path: 'home',
    component: EmployeepListComponent
    },
    }

    Continue reading...

Compartilhe esta Página