I want to create a link to the route with multiple parameters and bind them in tempalte. Until now, I've been doing this by executing the function on (click)
event, but I was wondering if it's possible within RouterLink
's binding.
Here is the function I use to bind parameters:
redirect() {
this._router.navigate( ['/category', { cat: this.category, page: this.page }]);
}
My route looks like:
{
path: 'category/:cat/:page',
component: PostComponent
}
Will I be able to do the same inside routerLink
directive?
To add multiple parameters with React Router, we can get the URL parameters from the useParams hook. <Route path="/:category/:id" exact component={ItemDetails} />; to add the category and id parameters to the Route . We call useParams to return an object with the id and category parameters.
Href is the basic attribute provided by Html to navigate through pages which reloads the page on click. routerLink is the attribute provided by angular to navigate to different components without reloading the page.
RouterLink for dynamic dataDynamic data or user-defined objects can be passed from Angular version 7.2 using the state object stored in History API. The state value can be provided using the routerLink directive or navigateByURL.
Yes it can be attached to div tag, your route is probably wrong try add / in front of route.
Yes, of-course, you could use routerLink
to form href
tag dynamically for navigation. Values in array where each value will get evaluated against Component context.
[routerLink]="['/category', category, page ]"
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