Reputation: 1304
In my component, I have a google map. If a user changes the center of the map, I would change my URL and add the new center lat-long in the URL so users can send it as a link. Something like this: http://myurl.com/map?center=lat!long
I use the new router of RC1
Upvotes: 0
Views: 1845
Reputation: 961
const appRoutes: Routes = [
{ path: 'map/:id', component: mapComponent }]; //id is optional
this.router.navigate(['map', '1', { 'center': 'taiwan' }]);
And the uri will be like this :
http://localhost:4200/map/1;center=taiwan
import {Router, ActivatedRoute} from '@angular/router';
export class mapComponent implements OnInit {
constructor(
private route: ActivatedRoute) {
}
ngOnInit() {
//Get route parameter
this.route.params.subscribe(params => {
let custIdValue = params['id'];
let centerValue = params['center'];
//Do somthing...
});
}
}
Reference : Angular Doc
Upvotes: 1
Reputation: 22705
the correct syntax now should be
this._router.navigate(['.'], {
queryParams: { center: this.variable },
relativeTo: this._route
});
Upvotes: 2
Reputation: 71
You could use:
this.router.navigate( [
'CurrentPage', { id: 'companyId', param1: 'value1'
}]);
Upvotes: 0