router5 / router5

Flexible and powerful universal routing solution
https://router5.js.org
MIT License
1.72k stars 105 forks source link

Open route in new tab by pressing Ctrl/Cmd/Meta #257

Closed vvhsk closed 6 years ago

vvhsk commented 6 years ago

Hi to all.

Is there any default method to open navigate (navigateTo) links in new tab when pressing ctrl, cmd or meta key?

troch commented 6 years ago

Ctrl or Cmd + click on an hyperlink opens a new tab, so it's not something your router can do (and should do) something about.

bradrydzewski commented 6 years ago

@troch I just wanted to quickly comment that I was looking for more information about this as well. Thanks in advance for the library and your support :)

If I use cmd+click in the redux demo it does not open in a new window as I would have expected.

I was looking through the code, and if I understand correctly, the ability to open in a new window with ctrl+cmd is predicated on your using a component for links that inherits from <BaseLink> (react) which handles the click event and checks for keys pressed. So if you are using the redux router without react (let's say polymer+redux or lit-html+redux) it looks like a custom element would be required to implement the same sort of on-click handling. Is my understanding correct?

troch commented 6 years ago

Oh I see, it is because .preventDefault is called, and there is no check for combo keys being pressed.

vvhsk commented 6 years ago

@troch Thanks, I understood this later after created the issue, I made this behaviour with custom handler. I had little misunderstanding that only <BaseLink> can handle key pressed in redux demo (as @bradrydzewski described). Maybe this should be documented somewhere?

troch commented 6 years ago

I think that's because the examples have not been updated for a while, but links have been checking for ctrl / meta / alt keys for a while now (https://github.com/router5/router5/blob/master/packages/react-router5/modules/BaseLink.js#L58-L61).