diff --git a/package.json b/package.json index 451c3cf..36a73d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wkitd", - "version": "1.3.11", + "version": "1.3.12", "type": "module", "main": "dist/index.js", "files": [ diff --git a/src/router/router-components.js b/src/router/router-components.js index d266365..9cf383e 100644 --- a/src/router/router-components.js +++ b/src/router/router-components.js @@ -21,13 +21,16 @@ class RouterView extends Component { set current(v) { let old = this.#current + let $refs = this.$refs this.#current = v + if (this.keepAlive) { if (old) { - if (this.$refs[old]) { - this.$refs[old].removed = true - this.$refs[old].deactivated() - this.$refs[old].remove() + let $old = $refs[old] + if ($old) { + $old.removed = true + $old.deactivated() + $old.remove() } else { this.$requestUpdate() } @@ -35,14 +38,15 @@ class RouterView extends Component { this.$requestUpdate() } if (v) { - if (this.$refs[v]) { - this.root.appendChild(this.$refs[v]) - this.$refs[v].$requestUpdate() + let $new = $refs[v] + if ($new) { + this.root.appendChild($new) + $new.$requestUpdate() if (this.transition) { - this.$refs[v].$animate() + $new.$animate() } - this.$refs[v].removed = false - this.$refs[v].activated() + $new.removed = false + $new.activated() } else { this.$requestUpdate() } @@ -72,20 +76,21 @@ class RouterView extends Component { { transform: 'translateX(0)', opacity: 1 } ] } + let name = this.current - if (this.current) { + if (name) { if (this.transition) { return raw( - `<${this.current} ref="${this.current}" ${ + `<${name} ref="${name}" ${ this.keepAlive ? 'keep-alive' : '' - } #animation="%s">`, + } #animation="%s">`, [option] ) } return raw( - `<${this.current} ref="${this.current}" ${ + `<${name} ref="${name}" ${ this.keepAlive ? 'keep-alive' : '' - }>` + }>` ) } }