我做了一个 gatsby-wordpress-starter 的 git 克隆(https://www.gatsbyjs.org/starters/?c=Wordpress)
在不做任何更改的情况下,我添加了姿势:(https://popmotion.io/pose/examples/route-transitions-reach-router/)
按照上面网址中的说明,我将 components/layout.js 文件更改为以下内容(略有不同,因为页面路径没有像示例那样硬编码到布局中):
import React from 'react'
import ReactDOM from 'react-dom';
import { Router, Link, Location } from '@reach/router';
import Helmet from 'react-helmet'
import Navbar from '../components/Navbar'
import Page from '../templates/page'
import './all.sass'
import posed, { PoseGroup } from 'react-pose';
const RouteContainer = posed.div({
enter: { opacity: 1, delay: 300, beforeChildren: 300 },
exit: { opacity: 0 }
});
const PosedRouter = ({ children }) => (
<Location>
{({ location }) => ( <PoseGroup>
<RouteContainer key={location.key}>
<Router location={location}>{children}</Router>
</RouteContainer>
</PoseGroup>
)}
</Location>
);
const TemplateWrapper = ({children}) => (
<div>
<Helmet title="Home | Gatsby + Netlify CMS" />
<Navbar />
<PosedRouter/>
{console.log(location)}
</div>
)
export default TemplateWrapper
当我运行它时,我得到: Uncaught TypeError: Cannot read property 'map' of undefined
如果我展开'location'的console.log,那里没有'key'
除此之外,我还尝试安装官方 gatsby 转换插件,但这也无法正常工作。它执行进入转换但不执行退出转换。它确实会触发退出的转换,但直到页面内容更改后才会触发。