2017-12-19 1 views
0

私はかなり混乱している著名なプロジェクトでAngularコードを見つけました。異なるコンポーネントと同じパスを持つ角度経路の目的は何ですか?

コードはAmazon Web Services' Cognito quickstart projectです。私が参照しているこのファイル、app.routes.tsにはアプリのルートが含まれています。ただし、2つのルートルートは同じパスを持ちますが、異なる宛先が指定されています。

{ 
    path: '', 
    redirectTo: '/home', 
    pathMatch: 'full' 
}, 
{ 
    path: '', 
    redirectTo: '/securehome', 
    pathMatch: 'full' 
} 

どのように同じパスを持つ2つのルートが存在することができますが、別の場所につながる:

論文は両方ルートルートですか?これでエラーが発生しなければ、それは少なくとも完全に役に立たないはずです。私がここで紛失しているものはありますか(このコードは彼が何をしているかを知っている人が書いたものです)?私は、次のいずれかのユースケースを見る見ることができます

const homeRoutes: Routes = [ 
    { 
     path: '', 
     redirectTo: '/home', 
     pathMatch: 'full' 
    }, 
    { 
     path: 'home', 
     component: HomeComponent, 
     children: [ 
      {path: 'about', component: AboutComponent}, 
      {path: 'login', component: LoginComponent}, 
      {path: 'register', component: RegisterComponent}, 
      {path: 'confirmRegistration/:username', component: RegistrationConfirmationComponent}, 
      {path: 'resendCode', component: ResendCodeComponent}, 
      {path: 'forgotPassword/:email', component: ForgotPassword2Component}, 
      {path: 'forgotPassword', component: ForgotPasswordStep1Component}, 
      {path: 'newPassword', component: NewPasswordComponent}, 
      {path: '', component: HomeLandingComponent} 
     ] 
    }, 
]; 

const secureHomeRoutes: Routes = [ 
    { 

     path: '', 
     redirectTo: '/securehome', 
     pathMatch: 'full' 
    }, 
    { 
     path: 'securehome', component: SecureHomeComponent, children: [ 
     {path: 'logout', component: LogoutComponent}, 
     {path: 'jwttokens', component: JwtComponent}, 
     {path: 'myprofile', component: MyProfileComponent}, 
     {path: 'useractivity', component: UseractivityComponent}, 
     {path: '', component: MyProfileComponent}] 
    } 
]; 

const routes: Routes = [ 
    { 
     path: '', 
     children: [ 
      ...homeRoutes, 
      ...secureHomeRoutes, 
      { 
       path: '', 
       component: HomeComponent 
      } 
     ] 
    }, 


]; 

export const appRoutingProviders: any[] = []; 

export const routing: ModuleWithProviders = RouterModule.forRoot(routes); 
+0

を想起させることができる最高の理由です。 –

答えて

0


はここで完全なコードです。彼は彼のルートのガードを使用したい

、これは ルートが確保名前と自宅の経路であるが、私は が子どもたちのために設定されている任意の警備員を参照してくださいscroll down toパソコンへ転送理由で、これは私が彼がかもしれないと思うものです は行っているか、スキップしています。

これは、この1つはひどく構成されたに見えますが、私は私はあなたが正しいと思います:)

関連する問題