Sunday, 20 September 2020

How to write condition in route in angular / ionic

I'm using ionic 5 framework to build an application , I want to add condition in route if user already signed in before change route .

app-routing.module.ts file :

const routes: Routes = [
    {
        path: '',
        redirectTo: 'home',
        pathMatch: 'full'
    },
    {
        path: 'home',
        loadChildren: './home/home.module#HomePageModule'
    },
    {
        path: 'doctors',
        loadChildren: () => import('./doctors/doctors.module').then(m => m.DoctorsPageModule)
    },
    {
        path: 'dashboard',
        loadChildren: () => import('./user/dashboard/dashboard.module').then(m => m.DashboardPageModule),
        canLoad: [AuthGuard],
    },
];

@NgModule({
    imports: [
        RouterModule.forRoot(routes, {preloadingStrategy: PreloadAllModules})
    ],
    exports: [RouterModule]
})
export class AppRoutingModule {
}

I want to add condition here :

       {
            path: '',
            redirectTo: 'home',
            pathMatch: 'full'
        },

if user already signed change redirectTo: 'home' to be redirectTo: 'dashboard' how can i do this ?

Note : I'm used AuthGuard to prevent user from signed into some routs



from How to write condition in route in angular / ionic

No comments:

Post a Comment