1
我正在與Angular 2掙扎。我已經定義了所有的路由,但是當我輸入例如「mysiteurl:4200/password-recovery」或「mysiteurl:4200/email-confirm/sometoken」它驅使我隨機到家/配置組件(不需要)或密碼恢復或電子郵件確認組件(所需)。我不明白,重定向到家庭/配置文件。有任何想法嗎?角2:隨機路由
該應用程序的路由模塊代碼:
const appRoutes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'password-recovery', component: PasswordRecoveryComponent },
{ path: 'email-confirm/:token', component: EmailConfirmComponent },
{ path: 'home', component: HomeComponent,
children: [
{ path: '', redirectTo: 'profile', pathMatch: 'full' },
{ path: 'profile', component: ProfileComponent },
{ path: 'companies', component: CompaniesComponent },
{ path: 'roles', component: RolesComponent },
{ path: 'documents/:type', component: DocumentsComponent },
{ path: 'users', component: UsersComponent },
{ path: 'documents-identity', component: DocumentsIdentityComponent },
{ path: 'forms', component: FormsComponent },
{ path: 'password-recovery-detail', component: PasswordRecoveryDetailComponent },
{ path: 'card', component: CardComponent },
]
}
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes, { useHash: true })
],
exports: [
RouterModule
]
})
export class AppRoutingModule { }
你配置'useHash'爲您導航。所以導航使用哈希方法:'mysiteurl:4200 /#/ password-recovery' – mrkosima
它不會影響結果..有時密碼恢復,有時在家/配置文件 –