【发布时间】:2019-01-19 22:14:15
【问题描述】:
我需要角度路由器来匹配以给定前缀开头的任何路径到组件。这是我的路由器配置。
{
path: 'posts/:id/:title',
component: PostDetailsComponent
}
当我使用router.navigate() 导航到类似/posts/1/json-web-token-(jwt)-authentication-with-asp.net-core-2.0 的路线时,一切正常,但一旦我尝试刷新页面,就会弹出一个错误
Cannot match any routes. URL Segment: 'jwt'
Error: Cannot match any routes. URL Segment: 'jwt'
at ApplyRedirects.noMatchError (router.js:1719)
我已经尝试了推荐的解决方案here,但它似乎不适用于我的具体情况。我也尝试将我的路由器配置更改为:
{
path: 'posts/:id/**',
component: PostDetailsComponent
}
但这只是在构建时出错了。有什么方法可以匹配以/posts/:id/ 开头的任何路线吗?
【问题讨论】:
-
您可以使用子路由来匹配您想要的方式
标签: angular typescript routing