本文整理汇总了TypeScript中@angular/router.Routes.forEach方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Routes.forEach方法的具体用法?TypeScript Routes.forEach怎么用?TypeScript Routes.forEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/router.Routes
的用法示例。
在下文中一共展示了Routes.forEach方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateRoutingInfo
function updateRoutingInfo(routes: Routes, path: string) {
routes.forEach(route => {
if(!route.data) { return; }
const fullLink = [path, route.path].join('/');
route.data.link = fullLink;
if(route.children) {
updateRoutingInfo(route.children, fullLink);
}
});
}
示例2:
{ path: "edit/:id", component: EditComponent, data: { title: "Edit Check" } },
{ path: "edit/:id/:copy", component: EditComponent, data: { title: "Copy Check" } },
{ path: "settings", component: SettingsComponent, data: { title: "Settings", noSettingsLink: true } },
{ path: "details/:id", component: DetailsComponent, data: { title: "Details" } },
{ path: "login", component: LoginComponent, data: { title: "Login", noDashboardLink: true } },
{ path: "user", component: UserComponent, data: { title: "User" } },
{ path: "init", component: InitComponent, data: { title: "SystemChecker Init", noDashboardLink: true } },
{ path: "**", component: PageNotFoundComponent, data: { title: "Not Found" } },
];
routes.forEach(x => {
if (!x.canDeactivate) {
x.canDeactivate = [];
}
x.canDeactivate.push(CanDeactivateGuard);
if (x.path === "login" || x.path === "init") { return; }
if (!x.canActivate) {
x.canActivate = [];
}
x.canActivate.push(AuthGuard);
});
@NgModule({
imports: [
CommonModule,
BrowserModule,
BrowserAnimationsModule,
HttpModule,
FormsModule,
RouterModule.forRoot(routes),
JwtModule.forRoot({
示例3:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { PlanOfWork } from './components/plan-of-work/plan-of-work';
import { TestSets } from './components/testset/testset';
export const mainMenuRoutes: Routes = [
{ path: 'planofwork', component: PlanOfWork },
{ path: 'testset', component: TestSets },
{ path: 'testing', component: PlanOfWork },
{ path: 'settings', component: PlanOfWork },
{ path: 'tools', component: PlanOfWork }
];
const routes: Routes = [
{ path: 'new', redirectTo: 'planofwork/12?regionId=13', pathMatch: 'full' },
{ path: 'planofwork/:id', component: PlanOfWork }
];
mainMenuRoutes.forEach(r => routes.push({ path: r.path, component: r.component }));
@NgModule({
imports: [
RouterModule.forRoot(
routes,
// { enableTracing: true } // <-- debugging purposes only
)
],
exports: [RouterModule]
})
export class AppRoutingModule { }