當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。