My empty default route is falling into the last set loading Lazy

Asked

Viewed 12 times

1

I have the following standard 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 hit my localhost without giving a route, the costx list component is loaded. I should not load the welcome module?

This is my Guard that leads to 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;
    }
  }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.