2016-08-27 26 views
1

我嘗試按照此tutorial添加引導程序導航欄到我的angualr2應用程序。routingConfig在angular2 RC中已棄用?

我已經從angular2 quick start頁面創建了我的應用程序。

重新開始使用angular2 CLI bootstrap是否更好?

但是我看到lib routingConfig已在angular2 RC中棄用。

是否有任何簡單的模板\教程是爲angualr2?

enter image description here

+0

[最新和最好的文檔](https://angular.io/docs/ts/latest/guide/router.html) – derelict

+1

另外,我的建議是如果可能的話帶一個帶有最新版本的教程,然後得到最新的一旦你的教程正確工作。 對於一個簡單的教程,你應該是一個非常簡單的官方教程,並且在觀看解決方案之前嘗試做他們所要求的,它會提供更好的知識。 –

回答

1

在Angular2RC5改變使用路由器的方式。

如果你想從RC4遷移到RC5,你可以閱讀官方文檔(https://angular.io/docs/ts/latest/cookbook/rc4-to-rc5.html)。

使用路由器的新方法如下(從官方文檔 - https://angular.io/docs/ts/latest/guide/router.html):

app.routing.ts

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

const appRoutes: Routes = [ 
    { path: 'crisis-center', component: CrisisCenterComponent }, 
    { 
    path: 'heroes', 
    component: HeroListComponent, 
    data: { 
     title: 'Heroes List' 
    } 
    }, 
    { path: 'hero/:id', component: HeroDetailComponent }, 
    { path: '**', component: PageNotFoundComponent } 
]; 

export const appRoutingProviders: any[] = [ 

]; 

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes); 

app.module.ts

import { AppComponent }  from './app.component'; 
import { routing, 
     appRoutingProviders } from './app.routing'; 

import { HeroListComponent } from './hero-list.component'; 
import { CrisisListComponent } from './crisis-list.component'; 

@NgModule({ 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    routing 
    ], 
    declarations: [ 
    AppComponent, 
    HeroListComponent, 
    CrisisListComponent 
    ], 
    providers: [ 
    appRoutingProviders 
    ], 
    bootstrap: [ AppComponent ] 
}) 
+0

通常使用angular2 CLI bootsrtap工具會更好嗎? –

+0

我在我的項目中使用angular-cli(https://github.com/angular/angular-cli),它已更新到最新版本(RC5 = ngModules +新路由器) – caballerog