在设置路线时使用角度2中的名称

时间:2016-09-07 00:42:58

标签: angular typescript angular2-routing

我有一个角度2应用程序,用角度2 beta 14编写。我正在升级到rc5。我使用的是最新的路由器,我的包json包含"@angular/router": "3.0.0-rc.1"

以前的路线配置如下:

{path:'/...',name:'LoggedIn',component:LoggedInComponent},
{path:'/auth', name:'Auth', component:AuthComponent}

现在我正在这样做

import { RouterModule , Routes } from '@angular/router';
import {AuthComponent} from "./auth/auth.component";
import {LoggedInComponent} from "./auth/logged-in.component";
import {LOGGED_IN_ROUTES} from "./auth/logged-in.routes";
const APP_ROUTES : Routes = [
    { path : '/...' , name :'LoggedIn' , component : LoggedInComponent , children : LOGGED_IN_ROUTES},
    { path : '' , component : AuthComponent},
    { path : 'auth' , component : AuthComponent},

];
export const routing = RouterModule.forRoot(APP_ROUTES);

我收到错误

Type '({ path: string; name: string; component: typeof LoggedInComponent; children: Route[]; } | { path...' is not assignable to type 'Route[]'.
  Type '{ path: string; name: string; component: typeof LoggedInComponent; children: Route[]; } | { path:...' is not assignable to type 'Route'.
    Type '{ path: string; name: string; component: typeof LoggedInComponent; children: Route[]; }' is not assignable to type 'Route'.
      Object literal may only specify known properties, and 'name' does not exist in type 'Route'.

2 个答案:

答案 0 :(得分:1)

name现已弃用,API自beta版以来已升级,您可以阅读更多相关信息here

要检查如何配置路由和Routes数组的模式,请参阅this

希望这会有所帮助!!

答案 1 :(得分:0)

通过数据键将其作为数据传递,如下所示:

{ path: 'your_path', component: yourComponent, data: { name: 'your_path_name' }}

了解更多:https://angular.io/guide/router#configuration