Skip to content
Permalink
Browse files

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

…18356)

* account for defaultHref, switch to serializer

* bug fix
  • Loading branch information...
liamdebeasi committed May 22, 2019
1 parent 62abb97 commit b79f68a77691fa39203487839f16abc8745df867
Showing with 13 additions and 7 deletions.
  1. +13 −7 angular/src/providers/nav-controller.ts
@@ -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);
}
}
}

0 comments on commit b79f68a

Please sign in to comment.
You can’t perform that action at this time.