Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 5 commands.reduce is not a function in router.navigate

Tags:

angular

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);
}
like image 280
Robbie Mills Avatar asked Mar 07 '18 05:03

Robbie Mills


People also ask

What is the use of angular router?

The Angular router is the fundamental block of the Angular platform. It enables developers to build Single Page Applications (SPAs) with multiple views and navigation between them. To navigate different routes, use the Angular router as it provides methods to navigate different routes using routerLink.

How to navigate imperatively in angular router?

There are two methods available on Angular’s Router class to navigate imperatively in your component classes: Router.navigate and Router.navigateByUrl. Both methods return a promise that resolve to true if the navigation is successful, null if there’s no navigation, false if the navigation fails or is completely rejected if there’s an error.

What is routerlink in angular?

In Angular, RouterLink is a directive for navigating to a different route declaratively. Router.navigate and Router.navigateByURL are two methods available to the Router class to navigate imperatively in your component classes. Let’s explore how to use RouterLink, Router.navigate, and Router.navigateByURL.

How to use Route array in angular 13?

In Angular 13, there is an app-routing.module.ts module file. In that file, you can define the routes array that contains objects. We can define a different path and component in those objects, and angular will map the path to that component accordingly. So it will render specific components to a particular path.


1 Answers

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

goToPage(link) {
  this.router.navigate([link]);
}
like image 52
ayush didwaniya Avatar answered Oct 17 '22 20:10

ayush didwaniya