区分空路径和无参数
Distinguishing Between Empty Path and No parameter
我想创建一个有两条路线的 angular 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
;路由参数将只是空的。
如果存在参数 :resultId
,我如何通知路由器它应该只匹配 ResultComponent
?
使用pathMatch: full
空路径路由配置如下:
export const MyAppRoutes: Routes = [
{ path: "", component: HomepageComponent, pathMatch: full },
{ path: ":resultId", component: ResultComponent },
];
我想创建一个有两条路线的 angular 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
;路由参数将只是空的。
如果存在参数 :resultId
,我如何通知路由器它应该只匹配 ResultComponent
?
使用pathMatch: full
空路径路由配置如下:
export const MyAppRoutes: Routes = [
{ path: "", component: HomepageComponent, pathMatch: full },
{ path: ":resultId", component: ResultComponent },
];