Can't bind to 'routerLink' since it is a known property

152 views Asked by At
//catgory.component.html
    `<li
    (click)="setCurrentCategory(category)"
    routerLink="/projects/category/{{ category.categoryId }}"
    *ngFor="let category of categories"
    [class]="getCurrentCategoryClass(category)"
  >
    {{ category.categoryName }}
  </li>`
//category.component.ts

     setCurrentCategory(category: Category) {
    this.currentCategory = category;
    console.log(category)

  }
//app-routing.module.ts

    `const routes: Routes = [
  { path: '', pathMatch: 'full', component: ProjectComponent },
  { path: 'projects', component: ProjectComponent },
  { path: 'projects/category/:categoryId', component: ProjectComponent },
  {
    path: 'projects/add',
    component: PorjectAddComponent,
    canActivate: [LoginGuard],
  },
  { path: 'login', component: LoginComponent },
];`

Description I shared the code snippets of the error that I think is caused by the Angular version. Router Link cannot be reached to the given address. I am waiting for your help in this matter. Error enter image description here

2

There are 2 answers

0
Sohaib El Mediouni On

import RouterModule in your module

0
Samba On

Hello that's work for me

<a [routerLink]="'yourLink'" ></a>

Don't forget to import RouterModule in your ap module.ts RouterModule.forRoot(routes)