Issue
I have implemented my login-component
as a library
and the first thing shown in myApp
is the login
page.
However, I don't know how to navigate to home
page after a successful login.
Does any one know how can I achieve it? Thank you.
Here is my app-routing.module.ts
:
import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{
path: '',
loadChildren: () => import('login').then(m => m.LoginPageModule)
},
{
path: 'home',
loadChildren: () => import('./home/home.module').then(m => m.HomePageModule)
},
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
],
exports: [RouterModule]
})
export class AppRoutingModule { }
Solution
I guess you should use something similar as below (I didn't check it):
In your component class instantiate Router and after success login redirect to another address:
import { Router } from '@angular/router';
constructor(
private route: Router,
) {}
// Your auth method
authUser(): void {
....
if (authSuccess) {
this.router.navigateByUrl('/home');
}
}
Answered By - Evgeny Gurevich
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.