【问题标题】:routerLinkActive with dynamic url doesn't work Angular 9带有动态url的routerLinkActive不起作用Angular 9
【发布时间】:2020-09-05 07:15:27
【问题描述】:

我有以下 html 模板:

<a [routerLink]="'/views/' + typeParam + '/my-recently-updated'" routerLinkActive="active">some text</a>

当我点击该链接时,我看到项目已被选中,但当我重新加载页面(按 F5)时,我看不到任何选定项目。

views-routing.module.ts:

const viewsRoutes: Routes = [
    {
        path: '',
        component: ViewsComponent,
        children: [
            { path: ':type', component: ViewsWrapperComponent },
            { path: ':type/:view_name', component: ViewsWrapperComponent }
        ]
    }
];

@NgModule({
    imports: [RouterModule.forChild(viewsRoutes)],
    exports: [RouterModule]
})
export class ViewsRoutingModule { }

我该如何解决这个问题?

【问题讨论】:

  • 你能把你的路由器模块问题吗?
  • @pc_coder 准备就绪

标签: angular angular-routerlink


【解决方案1】:

我是这样解决的:

<a [routerLink]="'/views/' + typeParam + '/my-recently-updated'" 
    routerLinkActive="active"
    [routerLinkActiveOptions]="{ __change_detection_hack__: typeParam }">some text</a>

在这里issue on github

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 1970-01-01
    • 2019-02-20
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    相关资源
    最近更新 更多