user3140824
user3140824

Reputation: 370

RouterLink work but function with router.navigate dont

My routerlink is working but after trying to convert it to a function it just does nothing. I have tried many things already: '/description' 'description' '/description/'.

before:

  <a [routerLink]="['description', course.id]">Go to description</a>

After (.html):

  <a (click)="goToDescription(course.id)">Go to description</a>

After (.ts):

  goToDescription(id) {
    this.router.navigate([`description`, id]);
  }

Route Description:

  {
    path: 'description/:course-id', component: CourseDescriptionComponent,
  },

Any help would be appreciated. Thanks!

Upvotes: 2

Views: 867

Answers (1)

user3140824
user3140824

Reputation: 370

I put the absolute url and it worked thanks to @Kamil Augustyniak who sent a link that helped me

  this.router.navigateByUrl(`/courses/description/${id}`);

Upvotes: 2

Related Questions