English | 中文
Shared element transitions between routers for React, Vue, Angular and Web applications. Idea from Hero Animations of Flutter, and other mobile applications.
yarn add react-shared-elementyarn add vue-shared-elementBoth routes use the SharedElement component and the id must to be the same. It can be a dynamic id and supports asynchronous.
import SharedElement from "react-shared-element"<SharedElement ref={this.ref} id='shared-id-123'>
Content of Component1
</SharedElement><div onClick={e => {
this.ref.current.redirect(() => this.props.history.push("/component2"))
}}>Go Component2</div>import SharedElement from "vue-shared-element"<shared-element ref="sharedElement" id="shared-id-123">
<div v-on:click="redirect">Go Home</div>
</shared-element><script>
import router from "../router"
import SharedElement from "vue-shared-element"
export default {
components: {
"shared-element": SharedElement
},
methods: {
redirect: function() {
this.$refs.sharedElement.redirect(() => router.push({ name: "home" }))
}
}
}
</script>| name | type | default | required |
|---|---|---|---|
id |
string | null | required |
duration |
number | 300 | optional |
zindex |
number | 1 | optional |
Enjoy coding!