我在一个突出的项目中遇到了一些Angular代码,我觉得相当混乱。
有问题的代码来自Amazon Web Services' Cognito quickstart project。我引用的这个文件app.routes.ts
包含应用程序的路由。但是,两条根路径具有相同的路径,但指定了不同的目的地。
这些 根路线:
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
},
{
path: '',
redirectTo: '/securehome',
pathMatch: 'full'
}
如何有两条路径相同但路径不同的路线?如果这不会导致错误,那么它至少应该是完全无用的吗?我在这里缺少什么(因为这段代码是由一个似乎知道他在做什么的人写的)?
以下是完整代码:
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)
我只能看到以下一个用例。
他想为他的路线使用警卫,这就是原因 路线是名称和家庭路线,但我没有看到任何警卫 为孩子配置,这是我认为他可能 正在做或已跳过。
这是我能想到的最好的理由:)