0

I'm trying to set a default route for my app, as the same way that I readed at the docs, but for some reason it's not setting a default route and redirecting to LoginComponent route.

Here is my app-routing.mudule.ts now:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './login/login.component';
import { HomeComponent } from './home/home/home.component';
import { AutenticacaoGuard } from './autenticacao/guard/autenticacao.guard';

const routes: Routes = [
  {
    path:'',
    pathMatch: 'full',
    redirectTo:'login'
  },
  {
    path: 'login',
    component:LoginComponent
  },
  {
    path: 'home',
    component:HomeComponent,
    canActivate:[AutenticacaoGuard]
  },
  {
    path: '**',
    redirectTo: 'login',
  },
];

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

My app.module.ts look like this now:

import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { RouterModule } from '@angular/router';
import { HomeModule } from './home/home.module';
import { PoModule } from '@po-ui/ng-components';
import { LoginModule } from './login/login.module';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { AppRoutingModule } from './app-routing.module';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HTTP_INTERCEPTORS } from 
'@angular/common/http';

@NgModule({
  declarations: [
  AppComponent,
],
 imports: [
 PoModule,
 NgbModule,
 HomeModule,
 FormsModule,
 LoginModule,
 BrowserModule,
 AppRoutingModule,
 HttpClientModule,
 RouterModule.forRoot([]),
],
providers: [
{
  provide:HTTP_INTERCEPTORS, 
  useClass:LoadingInterceptor,multi:true
}
],
bootstrap: [AppComponent]
})
export class AppModule { }

Someone know what's happening?

Hugo vilar
  • 101
  • 6

1 Answers1

0

I just removed the import of "LoginModule" and "HomeModule" from app.module.ts, and it works.

Hugo vilar
  • 101
  • 6