Skip to content

Commit 2db10a6

Browse files
committed
fix(MdButton): create better detection of router-link to support hmr
1 parent da24c63 commit 2db10a6

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/components/MdButton/MdButton.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
import MdComponent from 'core/MdComponent'
33
import ripple from 'core/mixins/ripple'
4+
import MdRouterLinkProps from 'core/MdRouterLinkProps'
45
import MdButtonContent from './MdButtonContent'
56
67
export default new MdComponent({
@@ -15,7 +16,8 @@
1516
type: String,
1617
default: 'button'
1718
},
18-
disabled: Boolean
19+
disabled: Boolean,
20+
to: null
1921
},
2022
render (createElement) {
2123
const buttonContent = createElement('md-button-content', {
@@ -48,8 +50,14 @@
4850
if (this.href) {
4951
tag = 'a'
5052
} else if (this.$router && this.to) {
51-
buttonAttrs.props = this.$props
53+
this.$options.props = MdRouterLinkProps(this, this.$options.props)
54+
5255
tag = 'router-link'
56+
buttonAttrs.props = this.$props
57+
delete buttonAttrs.props.type
58+
delete buttonAttrs.attrs.type
59+
delete buttonAttrs.props.href
60+
delete buttonAttrs.attrs.href
5361
}
5462
5563
return createElement(tag, buttonAttrs, [buttonContent])

src/components/MdButton/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
import MdRouterLinkProps from 'core/MdRouterLinkProps'
21
import MdButton from './MdButton'
32

43
export default Vue => {
5-
const props = new MdRouterLinkProps(Vue)
6-
7-
MdButton.props = {
8-
...MdButton.props,
9-
...props
10-
}
11-
124
Vue.component(MdButton.name, MdButton)
135
}

src/core/MdRouterLinkProps.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
export default Vue => {
2-
let props = Vue.options.components['router-link'].options.props
3-
1+
export default (context, props) => {
42
return {
53
...props,
6-
to: {
7-
type: props.to.type
8-
}
4+
...context.$options.components['router-link'].options.props
95
}
106
}

0 commit comments

Comments
 (0)