我想创建一个有两条路线的角度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
匹配?
使用pathMatch: full
与空路径路由配置如下:
export const MyAppRoutes: Routes = [
{ path: "", component: HomepageComponent, pathMatch: full },
{ path: ":resultId", component: ResultComponent },
];