2

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!

3
  • 2
    Look at this question stackoverflow.com/questions/33571605/… Commented Feb 5, 2020 at 18:47
  • One concern I'd have is that <a> is being used with onclick rather than routerLink/href in addition to no preventDefault() occurring in the handler. Commented Feb 5, 2020 at 18:53
  • @AlexanderStaroselsky I can change to div/button/whatever but the error continues ... Commented Feb 5, 2020 at 18:56

1 Answer 1

2

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}`);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.