Gatsby v2使用的是Reach路由器而不是React路由器,因此使用
getUserConfirmation
具有
replaceHistory
不会再工作了。在盖茨比v2 RC中你可以使用
react-pose
要更直接地创建页面转换,请执行以下操作:
盖茨比浏览器.js
和
盖茨比-ssr.js
:
import React from "react"
import Transition from "./src/components/transition"
export const wrapPageElement = ({ element, props }) => {
return <Transition {...props}>{element}</Transition>
}
过渡.js
组成部分:
import React from "react"
import posed, { PoseGroup } from "react-pose"
const timeout = 250
class Transition extends React.PureComponent {
render() {
const { children, location } = this.props
const RoutesContainer = posed.div({
enter: { delay: timeout, delayChildren: timeout },
})
// To enable page transitions on mount / initial load,
// use the prop `animateOnMount={true}` on `PoseGroup`.
return (
<PoseGroup>
<RoutesContainer key={location.pathname}>{children}</RoutesContainer>
</PoseGroup>
)
}
}
export default Transition
在你的内心
页
:
// Use `posed.div` elements anywhere on the pages.
const Transition = posed.div({
enter: {
opacity: 1,
},
exit: {
opacity: 0,
},
})
// ...
<Transition>Hello World!</Transition>
检查
official example
一个工作演示。