0

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

3 Answers 3

2

the correct syntax now should be

this._router.navigate(['.'], {
            queryParams: { center: this.variable },
            relativeTo: this._route
        });

Doc at Angular.io

Sign up to request clarification or add additional context in comments.

Comments

1

Routes

const appRoutes: Routes = [
{ path: 'map/:id', component: mapComponent }]; //id is optional

Navigate the route

this.router.navigate(['map', '1', { 'center': 'taiwan'  }]);

And the uri will be like this :

http://localhost:4200/map/1;center=taiwan

Map component

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

Comments

0

You could use:

this.router.navigate( [
  'CurrentPage', { id: 'companyId', param1: 'value1'
}]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.