Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support target="_blank" for <router-link> #830

Merged
merged 6 commits into from
Nov 13, 2016
Merged

Conversation

fnlctrl
Copy link
Member

@fnlctrl fnlctrl commented Oct 25, 2016

No description provided.

Copy link
Member

@phanan phanan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know how to use this GitHub review. Should have made it a comment instead :P

// don't redirect if `target="_blank"`
/* istanbul ignore if */
const target = this.$el && this.$el.attributes.getNamedItem('target')
if (target && target.value === '_blank') return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  • Why not const target = this.$el && this.$el.getAttribute('target')?
  • Won't this fail for target="_blank " (with an extra space)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, I guess I'm just too unfamiliar with native dom api 😂

// don't redirect if `target="_blank"`
/* istanbul ignore if */
const target = this.$el && this.$el.getAttribute('target')
if (target && target.toLowerCase().split(' ').indexOf('_blank') > -1) return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since code is written in ES Net, shouldn't it be target.toLowerCase().split(' ').includes('_blank')?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That cannot be transpiled, and would require a polyfill.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about just /\b_blank\b/i.test(target)

@LinusBorg LinusBorg added the 2.x label Oct 31, 2016
@posva
Copy link
Member

posva commented Nov 7, 2016

@fnlctrl I absolutely forgot about this, sorry

@fnlctrl
Copy link
Member Author

fnlctrl commented Nov 7, 2016

@posva Totally forgot this too 😂😂😂
I think I'll just wait for Evan to get back to this.

@@ -49,6 +49,11 @@ export default {
// don't redirect on right click
/* istanbul ignore if */
if (e.button !== 0) return
// don't redirect if `target="_blank"`
/* istanbul ignore if */
const target = this.$el && this.$el.getAttribute('target')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use e.target here. this.$el may be a wrapping <li> if tag prop is used.

// don't redirect if `target="_blank"`
/* istanbul ignore if */
const target = this.$el && this.$el.getAttribute('target')
if (target && target.toLowerCase().split(' ').indexOf('_blank') > -1) return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about just /\b_blank\b/i.test(target)

@yyx990803 yyx990803 merged commit a8902fb into dev Nov 13, 2016
@fnlctrl fnlctrl deleted the allow-target-blank branch November 14, 2016 21:26
@bedlate
Copy link

bedlate commented Jun 20, 2017

@yyx990803 , hello you da, but how can I do it in the instance, like this:

this.$router.push({name: 'users.index', target: '_blank'})

@Mouvedia
Copy link

Mouvedia commented Aug 8, 2017

If it's supported you should update this line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants