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

Time:06-13

//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

CodePudding user response:

Hello that's work for me

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

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

CodePudding user response:

import RouterModule in your module

  • Related