typescriptknockout.jssingle-page-applicationdurandal

How to open a new tab with router.navigate in TypeScript


The following typescript code will always open in the current browser tab

navigate($data: menuItem, $event: JQueryEventObject) {
       //...
       let a = $event.currentTarget as HTMLAnchorElement;
       router.navigate(a.href);    
    }

How do I make router.navigate open in a new tab ? (that is when $event.ctrlKey is true)


Solution

  • Yes, as you @Daneille commented, you have to handle by your own way since durandal's router plugin (navigate function) does not provide a way to open a new tab.

    So it is better to handle something as you commented.

    if ($event.ctrlKey) { 
        window.open(url); 
    }