如何将具有某些ID的路由重定向到人性化的网址并处理角度路由中的规范网址?

问题描述 投票:1回答:1

我有两个网址格式

example.com/posts/:postIdexample.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':这里没有帖子标题,因此会引发错误
  • 如何将postTitle附加到url并避免重复网址问题。
  • 遵循此模式有哪些最佳实践。

我没有标题,所以首先我需要使用postId,所以我们有一个发布数据解析器(PdResolver),

angular angular-routing canonical-link
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.