[英]Can't load component,, automatically redirect me to login page
I'm using Angular 7 to create an admin dashboard.我正在使用 Angular 7 创建管理仪表板。 I created a home page which supposed to be working before Login.我创建了一个主页,它应该在登录之前工作。 But the problem is that it doesn't work, it work only after Login, but before login I can see it loaded for 1 second on the screen, and then an automatic redirection to Login page.但问题是它不起作用,它只有在登录后才起作用,但在登录之前我可以看到它在屏幕上加载了 1 秒钟,然后自动重定向到登录页面。
You can see below my app.module code.您可以在我的 app.module 代码下方看到。
const appRoutes: Routes = [
{
path : '',
component: HomeComponent,
},
{
path : 'apps',
loadChildren: './main/apps/apps.module#AppsModule',
},
{
path : 'pages',
loadChildren: './main/pages/pages.module#PagesModule',
},
{
path : 'ui',
loadChildren: './main/ui/ui.module#UIModule'
},
{
path : '**',
redirectTo: 'apps/dashboards/analytics'
},
];
@NgModule({
declarations: [
AppComponent,
],
imports : [
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
RouterModule.forRoot(appRoutes),
TranslateModule.forRoot(),
InMemoryWebApiModule.forRoot(FakeDbService, {
delay : 0,
passThruUnknownUrl: true
}),
// Material moment date module
MatMomentDateModule,
// Material
MatButtonModule,
MatIconModule,
// Fuse modules
FuseModule.forRoot(fuseConfig),
FuseProgressBarModule,
FuseSharedModule,
FuseSidebarModule,
FuseThemeOptionsModule,
// App modules
LayoutModule,
AppStoreModule,
//spinner
NgxSpinnerModule,
HomeModule
],
providers : [
DatePipe,
MehdiService,
TokenService,
AuthService,
AfterLoginService,
ProfileService,
BeforeLoginService,
AcademyCourseService,
AcademyCoursesService,
{ provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptorService,
multi: true
}
],
bootstrap : [
AppComponent
]
})
export class AppModule
{
}
And here is the code of home.module :这是 home.module 的代码:
@NgModule({
declarations: [
HomeComponent
],
imports : [
],
})
export class HomeModule
{
}
Check your's TokenInterceptorService
.检查您的TokenInterceptorService
。
Check your's HomeComponent
html selector if it's inside any component only visible when logged in.检查您的HomeComponent
html 选择器是否在任何仅在登录时可见的组件内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.