【问题标题】:How to handle n number of parameter in Angular2/4 router?如何处理 Angular2/4 路由器中的 n 个参数?
【发布时间】:2017-04-06 11:40:24
【问题描述】:

在我的应用程序中,URLn 中可以有 n 个参数,然后它也可以有一个可选的跟随模式。 例如,URL 可以是

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}

如何为这些类型的 URL 构建路由模块?

【问题讨论】:

    标签: angular angular-ui-router angular2-routing angular2-router angular2-router3


    【解决方案1】:

    你的意思是这样吗?

    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}
    ])
    

    【讨论】:

    • 类似的东西,是的。但是:id1/:id2并不总是:id1/:id2,它可能是:id1/:id2/:id3/..../idn
    • 那么您希望能够指定无限数量的 id 吗?据我所知,这是不可能的。恐怕您需要按照我的示例指定每条路线。我不太确定你想通过这个实现什么,如果你给我一个例子,我可能会建议另一种方法?
    猜你喜欢
    • 1970-01-01
    • 2018-09-24
    • 2016-04-23
    • 2017-12-03
    • 1970-01-01
    • 1970-01-01
    • 2018-02-19
    • 2020-08-21
    • 2017-04-17
    相关资源
    最近更新 更多