Angular2路由,包含必需参数和可选参数

时间:2016-11-08 12:17:29

标签: angular

我需要创建一个包含必需参数和可选参数的路径,如下所示:

/search/chicacgo;place=restaurant;hour=19:00

我想允许通过以下任何路线进行搜索:

  • /search/chicago
  • /search/chicago;hours=19:00
  • /search/chicago/;place=restaurant

所以我根据文档创建了一条路线:

RouterModule.forRoot([
        { path: 'search/:city/', component: SearchResultsComponent }
])

为了接收/search/chicacgo;place=restaurant;hour=19:00,我应该像这样打电话给我的路由器:

this.router.navigate([
    '/search'. {
        city: 'chicago',
        place: 'restaurant',
        hour: '19:00'
    }
]);

但我收到一个错误: Unhandled Promise rejection: Cannot match any routes: 'search;city=chicago;place=restaurant;hour=19:00' ;

我该如何正确地做到这一点?在Angular2中是否可以同时使用必需和可选参数而不是?foo=bar查询?

1 个答案:

答案 0 :(得分:0)

解决方案:

<!DOCTYPE html>
<html>
    <body>
        <form action = "formprocess.php" method = "post">
            Your name : <input type = "text" name = "name"> <br>
            <input type = "submit">
        </form>
    </body>
</html>