0

在我的應用程序中,URLn中可以有n個參數,然後它也可以有一個可選的跟隨模式。 例如,URL可以是如何在Angular2/4路由器中處理n個參數?

http://example.com/{param1}

http://example.com/{param1}/constant/{id}

http://example.com/{param1}/{param2}/constant/{id}

http://example.com/{param1}/{param2}

http://example.com/{param1}/{param2}/{param3}

http://example.com/{param1}/{param2}/{param3}/constant/{id}

etc

如何爲這些類型的URL構建我的路由模塊?

回答

0

你是這個意思嗎?

RouterModule.forChild([ 
    { path: 'api/whatever/:id1/', component: ComponentName} 
    { path: 'api/whatever/:id1/dosomething/:id2', component: ComponentName} 
    { path: 'api/whatever/:id1/:id2', component: ComponentName} 
    { path: 'api/whatever/:id1/:id2/dosomething/:id3/dosomemore', component: ComponentName} 
]) 
+0

就是這樣的,是的。但是:id1 /:id2並不總是:id1 /:id2,它可能是:id1 /:id2 /:id3 /..../ idn – user1532043

+0

因此,您希望能夠指定不定數量的id?這從我所知道的是不可能的。你需要按照我的例子來指定每條路線。我不太確定你想通過這種方式實現什麼,如果你給我一個例子,我可以建議一種替代方法? –

相關問題