本文整理汇总了TypeScript中@angular/router.Routes类的典型用法代码示例。如果您正苦于以下问题:TypeScript Routes类的具体用法?TypeScript Routes怎么用?TypeScript Routes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Routes类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: String
const flatten = (parent: Array<string>, routes: Routes): Array<Route> =>
routes.reduce(
(prev, route: AngularRoute & {server?: boolean}) => {
const prepared = location.prepareExternalUrl(parent.concat(route.path || []).join('/'));
const path = prepared.replace(/(^\.|\*\*?)/g, String()).split(/\//g).filter(v => v);
return prev.concat({path, server: route.server}, flatten(path, route.children || []));
},
empty);
示例3:
import { Routes, RouterModule } from '@angular/router';
import { ServicesComponent } from './services.component';
const routes: Routes = [
{ path: 'services', component: ServicesComponent }
];
export const routing = RouterModule.forChild(routes);
export const routedComponents = routes.filter(r => r.component != undefined).map(r => r.component)
示例4:
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ViewExpenseComponent } from './expenses/view-expense.component';
import { userRoutes } from './users/user-routes';
// Route Configuration
let routes: Routes = [
{
path: '',
redirectTo: '/users',
pathMatch: 'full'
},
{ path: 'expenses', component: ViewExpenseComponent }
];
routes = routes.concat(userRoutes);
// Deprecated provide
// export const APP_ROUTER_PROVIDERS = [
// provideRouter(routes)
// ];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes);
示例5:
import {Routes, RouterModule} from '@angular/router';
import {FleetMainComponent} from "./modules/fleet/fleet.component";
const navRoutes: Routes = [
{
path: 'fleet',
component: FleetMainComponent
}
];
const appRoutes: Routes = [
{
path: '',
redirectTo: '/fleet',
pathMatch: 'full'
}
];
export const routing = RouterModule.forRoot(appRoutes.concat(navRoutes));
示例6: registerLocaleData
NgxChartsModule,
} from "@swimlane/ngx-charts";
registerLocaleData(localeGB);
export function JwtTokenGetter(): string {
return store.get("token");
}
const routes: Routes = [
{ path: "", redirectTo: "dashboard", pathMatch: "full" },
{ path: "dashboard", component: DashboardComponent, data: { title: "Dashboard", noDashboardLink: true } },
{ path: "edit", component: EditComponent, data: { title: "New Check" } },
{ 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) {
示例7:
mainMenuRoutes.forEach(r => routes.push({ path: r.path, component: r.component }));
示例8:
import { TrainerComponent } from './trainer/trainer.component';
import { WinnerComponent } from './winner/winner.component';
import { AcknowledgeComponent } from './acknowledge/acknowledge.component';
import { TesterComponent } from './tester/tester.component';
const dev = false;
const routes: Routes = [
{ path: '', redirectTo: '/signin', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'board', component: BoardComponent },
{ path: 'starter', component: StarterPokemonComponent },
{ path: 'lobby', component: LobbyComponent },
{ path: 'capture', component: CapturePokemonComponent },
{ path: 'city', component: CityComponent },
{ path: 'event', component: EventComponent },
{ path: 'winner', component: WinnerComponent },
{ path: 'signin', component: SigninComponent },
{ path: 'trainer', component: TrainerComponent },
{ path: 'resumelobby', component: ResumeLobbyComponent },
{ path: 'acknowldedge', component: AcknowledgeComponent },
];
if ( dev ) { routes.push( { path: 'tester', component: TesterComponent } ); }
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }