20

I'm sending a string as a link to my router, eg "/blog/pages/3"

However I'm getting the error "commands.reduce is not a function"

The navigate does work though, just the error shows up in the console

goToPage(link) {
  this.router.navigate(link);
}
7
  • try passing your Id in second argument, like this this.router.navigate(['/pageURL', id]);} Commented Mar 7, 2018 at 5:47
  • My ID is not '3' in this case, it's the whole string. My link variable is '/blog/pages/3' Commented Mar 7, 2018 at 5:57
  • Why the downvote? Commented Mar 7, 2018 at 5:57
  • but, your route have ID parameter you cant redirect directly using whole string, you need to pass ID. Commented Mar 7, 2018 at 5:59
  • 5
    Try navigateByUrl method. navigate expects a command array and you are passing a string. Commented Mar 7, 2018 at 6:10

1 Answer 1

50

The function should be written like this. Use square brackets in the parameter:

goToPage(link) {
  this.router.navigate([link]);
}
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.