element [Feature Request] Combine el-link with router-link

l2osamch  于 4个月前  发布在  其他
关注(0)|答案(7)|浏览(86)

Existing Component

Yes

Component Name

el-link

Description

There's no way to combine el-link with router-link .

<router-link to="foo">
  <el-link>foo</el-link>
<router-link>

It is <a><a>foo</a></a> , not permitted.

<router-link tag="span" to="foo">
  <el-link>foo</el-link>
<router-link>

Browser's status bar doesn't work.

to94eoyn

to94eoyn1#

got the same issue here, i've figured out how to specify the router tag as:

<router-link tag="el-link" type="primary" :to="{ name: 'routename', params: { id: item.id } }"> {{ Link }} </router-link>

but the primary style doesn't work properly, don't know why, maybe it's an issue. hope this helps

tzdcorbm

tzdcorbm2#

Here's my solutions:

<el-link type="primary" @click="$router.push({ name: 'routename' })">
{{ link }}</el-link>

use a normal el-link tag with a click event that pushes to the desired route :)

bttbmeg0

bttbmeg03#

I thought the v-slot API could solve this problem: https://router.vuejs.org/api/#v-slot-api-3-1-0

The code looks like this:

<router-link to="/foo" v-slot="{ href, navigate }">
  <el-link :href="href" @click="navigate">foo</el-link>
</router-link>

But el-link does not emit the click event when there is an href prop.

element/packages/link/src/main.vue

Lines 44 to 50 in bf534d9

| | handleClick(event) { |
| | if (!this.disabled) { |
| | if (!this.href) { |
| | this.$emit('click', event); |
| | } |
| | } |
| | } |

@iamkun
Why doesn't el-link emit the click event?

fcg9iug3

fcg9iug34#

I'm just using "route" menu item attribute like this:

<el-menu router="true">
   <el-menu-item route="projects">Projects</el-menu-item>
</el-menu>
rsaldnfx

rsaldnfx5#

This seems to work

<router-link to="/foo" custom v-slot="{ navigate, href }">
  <el-link :href="href" @click.native="navigate">foo</el-link>
</router-link>
exdqitrt

exdqitrt6#

Here's my solutions:

<el-link type="primary" @click="$router.push({ name: 'routename' })">
{{ link }}</el-link>

use a normal el-link tag with a click event that pushes to the desired route :)

the problem was done, thanks

ltskdhd1

ltskdhd17#

Here is my solution:

<router-link custom to="/about" v-slot="{ navigate, href, route }">
   <el-link :href="href" @click="navigate">{{ route.fullPath }}</el-link>
</router-link>

doing this you can completly wrap the el-link inside a router-link without render the router link but keeping its behavoir.
The magic thing here is the custom attribute who tell router-link to not render anything !

相关问题