首页 > 解决方案 > 忽略部分路由路径

问题描述

我的 Angular 6 应用程序中的一条路线定义如下 -

{ path: 'product/:productId', component: ProductPageComponent }

现在,我想处理这样的 URL /product/BEV15733/Raw-Apple-Cider-Vinegar(即我想忽略第三个路径段)。但是,在导航时,Angular 会抛出错误,例如 -

错误:无法匹配任何路由。URL 段:'product/BEV15733/Raw-Apple-Cider-Vinegar'

标签: angularangular6angular-routing

解决方案


也许这会起作用:

{ path: 'product/:productId/:ignoreParam', component: ProductPageComponent }

使用 ':' 你希望你的 url 中有一个参数,你可以忽略这最后一段。


推荐阅读