fix(router): accepts root direction

This commit is contained in:
Manu Mtz.-Almeida
2018-05-11 18:56:29 +02:00
parent 0b27696d30
commit ae9d0c7236
6 changed files with 61 additions and 51 deletions

View File

@@ -64,7 +64,7 @@ export function getClassMap(classes: string | string[] | undefined): CssClassMap
return map;
}
export type RouterDirection = 'forward' | 'back';
export type RouterDirection = 'forward' | 'back' | 'root';
export async function openURL(win: Window, url: string|undefined, ev: Event, direction: RouterDirection = 'forward') {
if (url && url[0] !== '#' && url.indexOf('://') === -1) {
@@ -72,8 +72,14 @@ export async function openURL(win: Window, url: string|undefined, ev: Event, dir
if (router) {
ev && ev.preventDefault();
await router.componentOnReady();
return router.push(url, direction === 'back' ? -1 : 1);
return router.push(url, DIRECTION_MAP[direction]);
}
}
return Promise.resolve();
}
const DIRECTION_MAP = {
'back': -1,
'root': 0,
'forward': 1
};