我想创建一个有两条路线的角度SPA:
http://mydomain/ <- Shows homepage
http://mydomain/2017 <- Shows results for 2017
http://mydomain/2018 <- Shows results for 2018
URL的2017
和2018
部分是控制器的参数。我试图使用以下路线实现这一目标:
export const MyAppRoutes: Routes = [
{ path: "", component: HomepageComponent },
{ path: ":resultId", component: ResultComponent },
];
但是,访问http://mydomain
会呈现ResultComponent
;路线参数只是空的。
如果参数ResultComponent
存在,如何通知路由器它只应与:resultId
匹配?
答案 0 :(得分:2)
使用pathMatch: full
空路径路由配置,如下所示:
export const MyAppRoutes: Routes = [
{ path: "", component: HomepageComponent, pathMatch: full },
{ path: ":resultId", component: ResultComponent },
];