演示和代码 => https://codesandbox.io/s/73ymn2k911
根据我通过开发工具的观察,它最初知道在哪里放置组件但忘记设置opacity: 1
或删除旧组件
我怀疑问题出在 app.js请参阅下面的更新。
import React, { Component } from "react";
import { Route, matchPath } from "react-router-dom";
import TransitionGroup from "react-transition-group/TransitionGroup";
import AnimatedSwitch from "./animated_switch";
import { firstChild } from "../utils/helpers";
import TopBar from "./top_bar";
import Home from "./home";
import Projects from "./projects";
import ProjectItem from "./project_item";
import Missed from "./missed";
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
projects: []
};
}
componentDidMount() {
fetch("https://jsonplaceholder.typicode.com/posts")
.then(response => {
return response.json();
})
.then(json => {
this.setState({
projects: json.slice(0, 7)
});
});
}
render() {
return (
<div className="wrapper">
<TopBar />
<Route
render={({ location }) => (
<TransitionGroup component="main">
<AnimatedSwitch
key={location.pathname}
location={location}
>
<Route exact path="/" component={Home} />
<Route
exact
path="/projects"
render={props => (
<Projects {...props} projects={this.state.projects} />
)}
/>
<Route
path="/projects/:id"
render={props => (
<ProjectItem {...props} projects={this.state.projects} />
)}
/>
<Route component={Missed} />
</AnimatedSwitch>
</TransitionGroup>
)}
/>
</div>
);
}
}
但我可能是错的。单击codesandbox.io上的导航链接后,它会在其控制台上打印两个错误,这些错误在我的实时测试站点上的 chrome 开发工具未报告:
Warning: Unknown event handler property `onExited`. It will be ignored.
Warning: Received `true` for a non-boolean attribute `in`.
这一切都基于我去年在博客上发布的旧依赖项的示例。我正在尝试从示例中学习,并且很难让您了解每 6 个月更改一次的内容。
如果你能帮忙,谢谢!
更新:我一直在查看 react-transition-group v1 到 v2迁移指南,我认为问题实际上是我的转换组件,我不知道如何修复。