2017-08-24 15 views
0

platform-server/universalアプリでget paramsを使用して経路を記述しようとしていますが、これまでのところ成功していません。角度プラットフォームサーバ(ユニバーサル):取得パラメータを使用した経路

誰もが達成を定義する方法を知っていますか?

export const ROUTES: string[] = [ 
    '/', 
    '/item/:id' 
]; 

main.server.ts:

ROUTES.forEach((route: string) => { 
    app.get(route, (req: Request, res: Response) => { 
    res.render('../dist/index', { 
     req: req, 
     res: res 
    }); 
    }); 
}); 
私は次のことを試してみました expressルーティングから知っているが、私はエラーに

routes.tsに直面して終わる何に基づいて

私のコンポーネント:

constructor(private route: ActivatedRoute) { 

    } 

ngOnInit() { 
    this.sub = this.route.params.subscribe(params => { 
     console.log(params['id']); 
    }); 
} 
このコードでは

、サーバーnpm startがエラーなしで開始されたが、私はhttp://localhost:8000/item/thisistheparamを呼び出すときに、私は、ブラウザのコンソールで次のエラーに直面

Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'item/thisistheparam'

答えて

0

おっと、私は問題を見つけ、私はあまりにも私の怠惰なモジュールへのパスを追加するのを忘れ。私item.module.tsでそれぞれ)

@NgModule({ 
    declarations: [ItemView], 
    imports: [ 
    RouterModule.forChild([ 
     { path: ':id', component: PublicItemView, pathMatch: 'full'} 
    ]) 
    ] 
}) 

魅力のように働いている場合、私はpath: ':id'とすべてにpath: ''を変更し、今

関連する問題