Skip to content

Commit b79f68a

Browse files
authored
fix(angular): account for query params and fragments within a string (#18356)
* account for defaultHref, switch to serializer * bug fix
1 parent 62abb97 commit b79f68a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

angular/src/providers/nav-controller.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Location } from '@angular/common';
22
import { Injectable, Optional } from '@angular/core';
3-
import { NavigationExtras, NavigationStart, Router, UrlTree } from '@angular/router';
3+
import { NavigationExtras, NavigationStart, Router, UrlSerializer, UrlTree } from '@angular/router';
44
import { NavDirection, RouterDirection } from '@ionic/core';
55

66
import { IonRouterOutlet } from '../directives/navigation/ion-router-outlet';
@@ -29,6 +29,7 @@ export class NavController {
2929
constructor(
3030
platform: Platform,
3131
private location: Location,
32+
private serializer: UrlSerializer,
3233
@Optional() private router?: Router,
3334
) {
3435
// Subscribe to router events to detect direction
@@ -190,13 +191,18 @@ export class NavController {
190191
* would change the url, so things like queryParams
191192
* would be ignored unless we create a url tree
192193
* More Info: https://github.com/angular/angular/issues/18798
193-
*
194-
* Additionally, the router does some encoding under the hood,
195-
* so make sure we are not encoding special characters more than once
196194
*/
197-
return this.router!.navigateByUrl(
198-
this.router!.createUrlTree([decodeURIComponent(url.toString())], options)
199-
);
195+
const urlTree = this.serializer.parse(url.toString());
196+
197+
if (options.queryParams !== undefined) {
198+
urlTree.queryParams = { ...options.queryParams };
199+
}
200+
201+
if (options.fragment !== undefined) {
202+
urlTree.fragment = options.fragment;
203+
}
204+
205+
return this.router!.navigateByUrl(urlTree);
200206
}
201207
}
202208
}

0 commit comments

Comments
 (0)