当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript RouterModule.forRoot方法代码示例

本文整理汇总了TypeScript中@angular/router.RouterModule.forRoot方法的典型用法代码示例。如果您正苦于以下问题:TypeScript RouterModule.forRoot方法的具体用法?TypeScript RouterModule.forRoot怎么用?TypeScript RouterModule.forRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@angular/router.RouterModule的用法示例。


在下文中一共展示了RouterModule.forRoot方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { HomeContainer } from './home';
import { LoginContainer, LoginGuard } from './login';

const ROUTES: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: 'login', component: LoginContainer, canActivate: [ LoginGuard ] },
  { path: 'admin', loadChildren: () => System.import('./+admin/admin.module') }
];

export const ROUTING: ModuleWithProviders = RouterModule.forRoot(ROUTES, { useHash: false });
开发者ID:websublime,项目名称:kong-console,代码行数:13,代码来源:container.routes.ts

示例2:



import { RouterModule, Routes } from '@angular/router';
import { UserComponent } from "./user/user.component";
import { HomeComponent } from "./home-component.component";
import { USER_ROUTES } from "./user/user.routes";
import { DataDrivenComponent } from "./11_Forms/data-driven/data-driven.component";
import { TemplateDrivenComponent } from "./11_Forms/template-driven/template-driven.component";


const APP_ROUTES: Routes = [
    { path: 'user', redirectTo: '/user/1', pathMatch: 'full' },
    { path: 'user/:id', component: UserComponent },
    { path: 'user/:id', component: UserComponent, children: USER_ROUTES },
    //{ path: '', component: HomeComponent }
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    { path: 'home', component: HomeComponent },

    //11 Forms
    { path: 'formsData', component: DataDrivenComponent },
    { path: 'formsTemplate', component: TemplateDrivenComponent },

    { path: '**', redirectTo: '/user/2', pathMatch: 'full' }

];


export const routing = RouterModule.forRoot(APP_ROUTES);
//export const APP_ROUTES_PROVIDER = [
//    provideRoutes(APP_ROUTES)
//];
开发者ID:vaibahv88sharma,项目名称:GitCodes,代码行数:29,代码来源:app.routing.ts

示例3:

import { Routes, RouterModule } from "@angular/router";

import { MessagesComponent } from "./messages/messages.component";
import { AuthenticationComponent } from "./auth/authentication.component";

const appRoutes: Routes = [
  {
    // Root path setup
    path: '',
    redirectTo: '/messages',
    pathMatch: 'full'
  },
  {
    path: 'messages',
    component: MessagesComponent
  },
  {
    path: 'auth',
    component: AuthenticationComponent,
    // Implementation of nested routes
    // It's loaded only when needed
    loadChildren: './auth/auth.module#AuthModule'
  }
];

// Register all routes and export it
export const routing = RouterModule.forRoot(appRoutes);
开发者ID:freesk,项目名称:angular2-messenger,代码行数:27,代码来源:app.routing.ts

示例4:

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule, PreloadAllModules } from '@angular/router';

import { AppComponent } from './app.component';
import { LandingComponent } from './landing/landing.component';
import { LogInComponent } from './login/login.component';
import { NgrxDashBoardComponent } from './ngrx/dashboard.component';

import { LogInGuard } from './shared/services/login.guard';

const routes: Routes = [
  { path: '', component: LandingComponent, canActivate: [LogInGuard] },
  { path: 'login', component: LogInComponent, canActivate: [LogInGuard] },
  { path: 'ngrx', component: NgrxDashBoardComponent, canActivate: [LogInGuard] },
  {
    path: '*',
    redirectTo: '/',
    pathMatch: 'full'
  }
];

export const routing: ModuleWithProviders =
  RouterModule.forRoot(routes, {
    preloadingStrategy: PreloadAllModules
  })
  ;
开发者ID:rsanabria,项目名称:orange2,代码行数:26,代码来源:app.routes.ts

示例5:

import { AuthGuard } from './common/auth.guard';
import { HomeComponent } from './components/home/home.component';
import { LoginComponent } from './components/login/login.component';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { ErrorComponent } from './components/error/error.component';

export const routing = RouterModule.forRoot([
    {
        path: '',
        pathMatch: 'full',
        component: HomeComponent
    },
    {
        path: 'login',
        component: LoginComponent
    },
    {
        path: 'dashboard',
        component: DashboardComponent,
        canActivate: [AuthGuard]
    },
    {
        path: 'error',
        component: ErrorComponent
    },
    {
        path: '**',
        redirectTo: 'error'
    }
]);
开发者ID:matthias-schuetz,项目名称:angular2-seed,代码行数:30,代码来源:routes.ts

示例6:

import {DashboardComponent} from './dashboard/dashboard.component';
import {RouterModule} from '@angular/router';
import {SettingsComponent} from './settings/settings.component';

const routes = [
  // {path: '', loadChildren: 'src/app/dashboard/dashboard.module'},
  {path: '', component: DashboardComponent},
  // {path: 'settings', loadChildren: 'app/settings/settings.module'},
  {path: 'settings', component: SettingsComponent}
];

export default RouterModule.forRoot(routes);
开发者ID:Den-dp,项目名称:angular2-dashboards-app,代码行数:12,代码来源:app.routes.ts

示例7:

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { HeroesComponent } from './heroes.component';
import { DashboardComponent } from './dashboard.component';
import { HeroDetailComponent } from './hero-detail.component';

const appRoutes: Routes = [
    {
        path: 'heroes',
        component: HeroesComponent
    },
    {
        path: 'dashboard',
        component: DashboardComponent
    },
    {
        path: '',
        redirectTo: '/dashboard',
        pathMatch: 'full'
    },
    {
        path: 'detail/:id',
        component: HeroDetailComponent        
    }
];

export const routing: ModuleWithProviders 
    = RouterModule.forRoot(appRoutes);
开发者ID:jumpt57,项目名称:angular2-tests,代码行数:29,代码来源:app.routing.ts

示例8:

const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  {
    path: '',
    data,
    component: LayoutComponent,
    children: [
      { path: 'components', loadChildren: './components/components.module#ComponentsModule' },
      { path: 'docs', loadChildren: './docs/docs.module#DocsModule' },
      { path: 'home', loadChildren: './home/home.module#HomeModule' },
      { path: 'interface', loadChildren: './interface/interface.module#InterfaceModule' },
      { path: 'profile', loadChildren: './profile/profile.module#ProfileModule' },
      { path: 'forms', loadChildren: './forms/forms.module#FormsModule' },
      { path: 'gallery', loadChildren: './gallery/gallery.module#GalleryModule' },
      { path: 'messages', loadChildren: './messages/messages.module#MessagesModule' },
      { path: 'empty', children: []},
    ],
  },
  {
    path: '',
    data,
    component: LayoutBaseComponent,
    children: [
      { path: '', loadChildren: './auth/auth.module#AuthModule' },
      { path: '**', redirectTo: '/404?message=Invalid route' },
    ],
  },
]

export const AppRoutingModule: ModuleWithProviders = RouterModule.forRoot(routes)
开发者ID:iwe7,项目名称:tabler-angular,代码行数:30,代码来源:app-routing.module.ts

示例9:

import { RouterModule } from "@angular/router";
import { ModuleWithProviders }  from '@angular/core';

import { appRoutes } from './app.routes';

export const appRouting: ModuleWithProviders = RouterModule.forRoot(appRoutes, { useHash: true });
开发者ID:rajayogan,项目名称:angular2-new-authentication,代码行数:6,代码来源:app.routing.ts

示例10:

import {Router, RouterModule} from '@angular/router';
import {HomeComponent} from './home.component';
import {MessagesComponent} from './messages/messages.component';
import {PhotosComponent} from './photos/photos.component';
import {NotFoundComponent} from './not-found.component';

export const routing = RouterModule.forRoot([
    {path:'', component: HomeComponent},
    {path:'messages', component: MessagesComponent},
    {path:'photos', component: PhotosComponent},
    {path:'**', component: NotFoundComponent},
]);
开发者ID:basanirakesh,项目名称:Angular-JS-2,代码行数:12,代码来源:app.routing.ts


注:本文中的@angular/router.RouterModule.forRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。