I'm using Angular. In my AppComponent
, I would like to display a login page if the user is not logged.
I have an Authentication service
export class AuthenticationService {
constructor() {}
logout() {
// logs out user
}
login(user) {
//logs in user
}
checkCredentials() {
//checks if logged in
}
}
app.component.ts
import { NgModule, Component } from '@angular/core';
// import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
@NgModule({
})
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
}
login.component
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
What can I do in app.component for the main page to load the LoginComponent
if user isn't logged in or DashboardComponent
if user is logged in without routing to different urls?