【发布时间】:2020-02-17 19:47:58
【问题描述】:
这里是 Angular 的新手。我的 app.module.ts 中有以下内容
RouterModule.forRoot()
{
...
{
path : "posts/:id",
component: PostprofileComponent
},
{
path : "posts",
component: PostsComponent
},
...
}
以下内容正确重定向到PostprofileComponent。
但是这个链接没有...它重定向到 PostsComponent。
http://localhost:4200/posts?id=2
他们的行为不应该一样吗?我做错了什么?
【问题讨论】:
-
你做错了什么?您期望它们的行为相同。它们不一样。
-
Angular 中的查询参数允许跨应用程序中的任何路由传递可选参数。查询参数不同于常规路由参数,后者仅在一个路由上可用,不是可选的(例如:
/posts/:id)。