ค้นหาเว็บไซต์

typescript - การใช้ชื่อใน Angular 2 เมื่อกำหนดเส้นทาง


ฉันมีแอป Angular 2 ซึ่งเขียนใน Angular 2 beta 14 ฉันกำลังอัปเกรดเป็น rc5 ฉันกำลังใช้ router เวอร์ชันล่าสุด ไฟล์ package.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'.

คำตอบ #1

name ไม่ได้รับการสนับสนุนแล้ว API ได้รับการอัปเกรดตั้งแต่ช่วงเบตา คุณสามารถอ่านเพิ่มเติมเกี่ยวกับมันได้ที่นี่

เพื่อดูวิธีการกำหนดค่าเส้นทางและโครงสร้างของอาเรย์ Routes ดูที่นี่

หวังว่านี่จะช่วยได้นะ!!

คำตอบ #2

ส่งมันเป็นข้อมูลผ่านคีย์ข้อมูล ดังนี้:

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

อ่านเพิ่มเติม: https://angular.io/guide/router#configuration