I'm new to Angular and I've looked for solution of my problem, but unfortunately I haven't found that. When I 'm passing parameters to the router (class Router), but list of params (on target site) is empty.
let navigationExtras: NavigationExtras ={
queryParams: {
uri: item.uri
}
}
this.router.navigateByUrl('articlelist/article-details', navigationExtras);
Article-details component (route is ActivatedRoute class):
ngOnInit(): void {
console.log("ArticleDetailsComponent " + JSON.stringify(this.route.url));
this.route.queryParamMap.map(paramMap =>{
this.uri = paramMap.get('uri');
console.log(this.uri);
});
}
Routing in ArticleList module (one of modules in my project):
const routes: Routes = [{
path: '',
component: ArticleListComponent,
data: {
title: 'ArticleList'
},
},
{
path: 'article-details',
component: ArticleDetailsComponent,
data: {
title: 'ArticleDetails'
},
}
];
When I logged route.url in target component the result was:
ArticleDetailsComponent {"_isScalar":false,"observers":[],"closed":false,"isStopped":false,"hasError":false,"thrownError":null,"_value":[{"path":"article-details","parameters":{}}]}
If somebody knows how to fixed it, I'll be grateful for help :)
pathMatch: 'full' means, that the whole URL path needs to match and is consumed by the route matching algorithm.
The query parameters feature in Angular lets you pass the optional parameters while navigating from one route to another.
Define your routes in your Routes array. Each route in this array is a JavaScript object that contains two properties. The first property, path , defines the URL path for the route. The second property, component , defines the component Angular should use for the corresponding path.
You should need to use ActivatedRoute
in order to get all query params.
Try this -
constructor(
private activatedRoute: ActivatedRoute
) { }
this.activatedRoute.queryParams.subscribe(params => {
const URI = params['uri'];
});
Try to send params like this -
this.router.navigate(['articlelist/article-details' ], {
queryParams: {
uri: item.uri || 'Default'
}
});
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