简体   繁体   中英

routerLinkActive with dynamic url doesn't work Angular 9

I have the following html template:

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

When I click on that link I see item is selected but when I reload page (press F5) then I see no selected items.

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 { }

How can I resolve this?

I resolved it this way:

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

as here issue on github

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM