我有两个网址格式
example.com/posts/:postId
和example.com/posts/:postId/:postTitle
就像堆栈溢出各个问题的URL。
在角度路由中,我需要将所有带有:postId
的URL重定向到:postId/:PostTitle
或直接将带有:postId/:PostTitle
平台的页面加载到同一页面。
post.module.ts
const routes: Routes = [
{
path: ':postId',
resolve: {data: PdResolver},
redirectTo: ':postId/:PostTitle',
pathMatch: 'full'
},
{
path: ':postId/:PostTitle',
component: PostComponent,
data: {
title: 'This has to be the post fetched title'
}
}
];
redirectTo: ':postId/:PostTitle'
:这里没有帖子标题,因此会引发错误我没有标题,所以首先我需要使用postId,所以我们有一个发布数据解析器(PdResolver),