10

I am fairly new to Angular 2 and do not know the correct terms to search for in order to get what i need.

I am using Angular 2 RC5 and the RouterModule in my app. When I pass params for a route to navigate to, Angular 2 Router automatically URL encodes it. Now although thats a good thing but is there a way to prevent it for certain params?

For example, I want to add comma separated values in the URL: http://localhost:4200/appcomponent/?data=abc1,abc2,abc3

What angular 2 makes it: http://localhost:4200/appcomponent/;data=abc1%2Cabc2%2Cabc3 (which looks rather messy)

Any suggestions how to make it more readable in URL?

Thanks!

Hassan
  • 2,308
  • 5
  • 21
  • 31
  • can you specify exact router library that you are using and provide your code? thanks! – wolendranh Aug 20 '16 at 07:57
  • I am using the default router library from Angular 2 (@angular/router: 3.0.0-rc.1) `let paramsObject = {data: 'abc1,abc2,abc3'}; this.router.navigate(['/appcomponent', paramsObject]);` – Hassan Aug 20 '16 at 09:26
  • check out my answer below for similar Question: http://stackoverflow.com/questions/41476193/angular-2-disable-url-encoding/41995695#41995695 – jigar gala Feb 02 '17 at 06:45
  • 1
    Possible duplicate of [angular 2 disable url encoding](http://stackoverflow.com/questions/41476193/angular-2-disable-url-encoding) – jigar gala Feb 02 '17 at 14:30

1 Answers1

14

You could navigate by Url instead:

 router.navigateByUrl('/parent/11/(simple//right:user/victor)');
null canvas
  • 10,201
  • 2
  • 15
  • 18