3
デフォルトルートで問題が発生しました。以前は正常に動作していましたが、ドメイン名/ルートページにアクセスすると、認証されたダッシュボードページにリダイレクトされますLazy NgModuleをロードし、認証されたユーザーの資格情報がないため、ログインページにリダイレクトされます。角度2のデフォルトルートが子ルートに変更されました
どうしてこのようなことが起こったのですか?最近、私は4.1.2に移動しましたが、問題の本当の原因ではありません。
私のルートは以下のとおりです。
import { Routes } from '@angular/router';
import { AppComponent } from './app.component';
import { HomeComponent } from './pages/home/home.component';
import { LoginComponent } from './pages/adviser/login/login.component';
// import { DashboardModule } from './pages/adviser/dashboard/dashboard.module'
import { Page404Component } from './pages/page404/page404.component';
import { AuthGuardService } from './shared/services/auth-guard.service';
import { PrivacyPolicyComponent } from './pages/privacy-policy/privacy-policy.component';
import { TermsConditionComponent } from './pages/terms-condition/terms-condition.component';
export const appRoutes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'login', component: LoginComponent },
{ path: 'privacy-policy', component: PrivacyPolicyComponent },
{ path: 'terms-condition', component: TermsConditionComponent },
{ path: 'dashboard', canActivate: [AuthGuardService], loadChildren: 'app/pages/adviser/dashboard/dashboard.module#DashboardModule' },
{ path: 'funds', loadChildren: 'app/pages/funds/funds.module#FundsModule' },
{ path: '', pathMatch: 'full', redirectTo: '/home' },
{ path: '**', pathMatch: 'full', component: Page404Component }
];
私app.moduleは次のとおりです。
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule, BrowserXhr } from '@angular/http';
import { RouterModule, Routes } from '@angular/router';
import { appRoutes } from './app.routes';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { ContactComponent } from './pages/contact/contact.component';
import { HomeComponent } from './pages/home/home.component';
import { LoginComponent } from './pages/adviser/login/login.component';
import { DashboardModule } from './pages/adviser/dashboard/dashboard.module';
import { Page404Component } from './pages/page404/page404.component';
import { HttpService } from './shared/services/http.service';
import { InstrumentService } from './shared/services/instrument.service';
import { WindowRef } from './shared/services/window-ref.service';
import { CredentialsService } from './shared/services/credentials.service';
import { ConstantService } from './shared/services/constant.service';
import { CryptService } from './shared/services/crypt.service';
import { AuthGuardService } from './shared/services/auth-guard.service';
import { PrivacyPolicyComponent } from './pages/privacy-policy/privacy-policy.component';
import { TermsConditionComponent } from './pages/terms-condition/terms-condition.component';
import { NgProgressModule, NgProgressCustomBrowserXhr } from 'ngx-progressbar';
import { Ng2PageScrollModule } from 'ng2-page-scroll';
@NgModule({
declarations: [
AppComponent,
ContactComponent,
HomeComponent,
LoginComponent,
Page404Component,
PrivacyPolicyComponent,
TermsConditionComponent
],
imports: [
NgProgressModule,
BrowserModule,
BrowserAnimationsModule,
Ng2PageScrollModule.forRoot(),
FormsModule,
HttpModule,
DashboardModule,
RouterModule.forRoot(appRoutes)
],
providers: [HttpService, CredentialsService, ConstantService,
AuthGuardService, CryptService, WindowRef,InstrumentService,
{ provide: BrowserXhr, useClass: NgProgressCustomBrowserXhr }],
bootstrap: [AppComponent]
})
export class AppModule { }
私Dashbaord.moduleは
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpService } from '../../../shared/services/http.service';
import { InstrumentService } from '../../../shared/services/instrument.service';
import { WindowRef } from '../../../shared/services/window-ref.service';
import { CredentialsService } from '../../../shared/services/credentials.service';
import { ConstantService } from '../../../shared/services/constant.service';
import { CryptService } from '../../../shared/services/crypt.service';
import { AuthGuardService } from '../../../shared/services/auth-guard.service';
import { AutoCompleteComponent } from '../../../shared/plugin/auto-complete/auto-complete.component';
import { MilliToDatePipe } from '../../../shared/pipes/milli-to-date.pipe';
import { PercentagePipe } from '../../../shared/pipes/percentage.pipe';
import { NseBsePipe } from '../../../shared/pipes/nse-bse.pipe';
import { INRCurrencyPipe } from '../../../shared/pipes/inr-currency.pipe';
import { NumberFormatPipe } from '../../../shared/pipes/num.pipe';
import { RiskPipe } from '../../../shared/pipes/risk.pipe';
import { LogPipe } from '../../../shared/pipes/log.pipe';
import { ChartsModule } from 'ng2-charts';
import { NgProgressModule, NgProgressCustomBrowserXhr } from 'ngx-progressbar';
import { Ng2PageScrollModule } from 'ng2-page-scroll';
import { InstrumentPipe } from '../../../shared/pipes/instrument.pipe';
import { TruncatePipe } from '../../../shared/pipes/truncate.pipe';
import { DashboardComponent} from './dashboard.component';
import { dashboardRouting } from './dashboard.routing';
@NgModule({
imports: [
CommonModule,
dashboardRouting,
ChartsModule,
FormsModule
],
declarations: [
DashboardComponent,
AutoCompleteComponent,
MilliToDatePipe,
PercentagePipe,
NumberFormatPipe,
INRCurrencyPipe,
NseBsePipe,
RiskPipe,
LogPipe,
InstrumentPipe,
TruncatePipe
],
providers: [HttpService, CredentialsService, ConstantService,
AuthGuardService, CryptService, WindowRef, InstrumentService]
})
export class DashboardModule { }
マイダッシュボードルーティングが
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard.component';
const dashboardRoutes: Routes = [
{ path: '', component: DashboardComponent }
];
export const dashboardRouting: ModuleWithProviders = RouterModule.forChild(dashboardRoutes);
です