Skip to content

Commit

Permalink
fix(angular): account for query params and fragments within a string (#…
Browse files Browse the repository at this point in the history
…18356)

* account for defaultHref, switch to serializer

* bug fix
  • Loading branch information
liamdebeasi committed May 22, 2019
1 parent 62abb97 commit b79f68a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions angular/src/providers/nav-controller.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit b79f68a

Please sign in to comment.