I have the following default route:
const dashboardRoutes: Routes = [
{ path: '', loadChildren: 'src/app/components/dashboard/bemvindo/bemvindo.module#BemVindoModule', canActivate: [AuthGuard] },
{path: 'dash', component: DashboardComponent, canActivate: [AuthGuard],
children: [
{ path: '', loadChildren: 'src/app/components/dashboard/bemvindo/bemvindo.module#BemVindoModule' },
{ path: 'home', loadChildren: 'src/app/components/dashboard/bemvindo/bemvindo.module#BemVindoModule' },
{ path: 'custofixo', loadChildren: 'src/app/components/dashboard/custofixo/custofixo.module#CustoFixoModule' },
{ path: 'custoextra', loadChildren: 'src/app/components/dashboard/custoextra/custoextra.module#CustoextraModule'},
{ path: 'custovariavel', loadChildren: 'src/app/components/dashboard/custovariavel/custovariavel.module#CustovariavelModule'},
{ path: 'listagemcustofixo', loadChildren: 'src/app/components/dashboard/customensalfixo/customensalfixocomponent#CustoMensalFixoModule'},
{ path: 'operador', component: OperadorComponent, pathMatch: 'full', canActivate: [CadOperadorGuard]},
{ path: 'produtos', component: ProdutoComponent, pathMatch: 'full'},
{ path: 'tipoprodutos', component: TipoprodutoComponent, pathMatch: 'full'},
{ path: 'meuperfil', component: MeuperfilComponent, pathMatch: 'full'},
{ path: 'confestoque', component: ConfEstoqueComponent, pathMatch: 'full'},
{ path: 'confprecificacao', component: ConfPrecificacao, pathMatch: 'full'},
{ path: 'monitoramento', component: MonitoramentoComponent, pathMatch: 'full'},
{ path: 'listagemcustovariavel', component: CustoMensalVariavel, pathMatch: 'full'},
{ path: 'listagemcustoextra', loadChildren: 'src/app/components/dashboard/customensalextra/customensalextra.module#CustoExtraModule'},
{ path: 'produtoscalculados', component: ProdutosCalculadosComponent, pathMatch: 'full'},
{ path: 'vinculacaoprodutosanuncios', component: Vinculacaoprodutosanuncios, pathMatch: 'full' },
]}
];
@NgModule({
imports: [RouterModule.forRoot(dashboardRoutes)],
exports: [RouterModule]
})
When I tap on my localhost without informing a route, the list component is loaded. Should not load the welcome module?
This is my guard that leads to the login screen if you do not have token:
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService,
private router: Router){}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | boolean {
if(localStorage.getItem('token') != null){ //Se encontrar o id da tela no array de permissoes, permite acessar a tela
return true;
}else{
this.router.navigate(['/login']);
return false;
}
}
}