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);
}
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.
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.
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.
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.
The function should be written like this. Use square brackets in the parameter:
goToPage(link) {
this.router.navigate([link]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With