fix(angular): account for query params and fragments within a string (#18356)

* account for defaultHref, switch to serializer

* bug fix
This commit is contained in:
Liam DeBeasi 2019-05-22 19:20:23 -04:00 committed by GitHub
parent 62abb972e9
commit b79f68a776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import { Location } from '@angular/common';
import { Injectable, Optional } from '@angular/core';
import { NavigationExtras, NavigationStart, Router, UrlTree } from '@angular/router';
import { NavigationExtras, NavigationStart, Router, UrlSerializer, UrlTree } from '@angular/router';
import { NavDirection, RouterDirection } from '@ionic/core';
import { IonRouterOutlet } from '../directives/navigation/ion-router-outlet';
@ -29,6 +29,7 @@ export class NavController {
constructor(
platform: Platform,
private location: Location,
private serializer: UrlSerializer,
@Optional() private router?: Router,
) {
// Subscribe to router events to detect direction
@ -190,13 +191,18 @@ export class NavController {
* would change the url, so things like queryParams
* would be ignored unless we create a url tree
* More Info: https://github.com/angular/angular/issues/18798
*
* Additionally, the router does some encoding under the hood,
* so make sure we are not encoding special characters more than once
*/
return this.router!.navigateByUrl(
this.router!.createUrlTree([decodeURIComponent(url.toString())], options)
);
const urlTree = this.serializer.parse(url.toString());
if (options.queryParams !== undefined) {
urlTree.queryParams = { ...options.queryParams };
}
if (options.fragment !== undefined) {
urlTree.fragment = options.fragment;
}
return this.router!.navigateByUrl(urlTree);
}
}
}