From af4bcb8dcf8c79b3a12637620a92d2e228dd0ab3 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Mon, 30 Apr 2018 14:16:38 +0200 Subject: [PATCH] fix(router): writeURL() for non root base --- core/src/components/router/utils/dom.ts | 11 ++++++++++- core/src/components/router/utils/path.ts | 10 ++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/core/src/components/router/utils/dom.ts b/core/src/components/router/utils/dom.ts index 449e603b55..b480619021 100644 --- a/core/src/components/router/utils/dom.ts +++ b/core/src/components/router/utils/dom.ts @@ -58,7 +58,16 @@ export function readNavState(root: HTMLElement | undefined) { return {ids, outlet}; } -const QUERY = ':not([no-router]) ion-nav,:not([no-router]) ion-tabs, :not([no-router]) ion-router-outlet'; +export function waitUntilNavNode(win: Window) { + if (searchNavNode(win.document.body)) { + return Promise.resolve(); + } + return new Promise((resolve) => { + win.addEventListener('ionNavWillLoad', resolve, { once: true }); + }); +} + +const QUERY = ':not([no-router]) ion-nav, :not([no-router]) ion-tabs, :not([no-router]) ion-router-outlet'; function searchNavNode(root: HTMLElement|undefined): NavOutletElement|null { if (!root) { diff --git a/core/src/components/router/utils/path.ts b/core/src/components/router/utils/path.ts index eacebeb0b2..eb2339fd76 100644 --- a/core/src/components/router/utils/path.ts +++ b/core/src/components/router/utils/path.ts @@ -26,10 +26,12 @@ export function chainToPath(chain: RouteChain): string[]|null { return path; } -export function writePath(history: History, base: string, usePath: boolean, path: string[], direction: RouterDirection, state: number) { - path = [base, ...path]; - let url = generatePath(path); - if (usePath) { +export function writePath(history: History, root: string, useHash: boolean, path: string[], direction: RouterDirection, state: number) { + let url = generatePath([ + ...parsePath(root), + ...path + ]); + if (useHash) { url = '#' + url; } if (direction === RouterDirection.Forward) {