|
1 | 1 | import { Location } from '@angular/common';
|
2 | 2 | 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'; |
4 | 4 | import { NavDirection, RouterDirection } from '@ionic/core';
|
5 | 5 |
|
6 | 6 | import { IonRouterOutlet } from '../directives/navigation/ion-router-outlet';
|
@@ -29,6 +29,7 @@ export class NavController {
|
29 | 29 | constructor(
|
30 | 30 | platform: Platform,
|
31 | 31 | private location: Location,
|
| 32 | + private serializer: UrlSerializer, |
32 | 33 | @Optional() private router?: Router,
|
33 | 34 | ) {
|
34 | 35 | // Subscribe to router events to detect direction
|
@@ -190,13 +191,18 @@ export class NavController {
|
190 | 191 | * would change the url, so things like queryParams
|
191 | 192 | * would be ignored unless we create a url tree
|
192 | 193 | * 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 |
196 | 194 | */
|
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); |
200 | 206 | }
|
201 | 207 | }
|
202 | 208 | }
|
|
0 commit comments