【发布时间】:2018-02-10 13:58:34
【问题描述】:
我试图找到一个使用 React Router v4 和 React Transition Group v2 的低级动画的工作示例。我查看了 React Router 文档上的示例,但他们只使用 CSS Animation 和一个路由。
这是我目前使用 React Router 的方式:
export const App = () => (
<div className="app-container">
<main className="app-container__content">
<Switch>
<Route exact path="/projects/:slug" component={ProjectPage} />
<Route exact path="/" component={StartPage} />
</Switch>
</main>
</div>
);
这是我的 Root.jsx:
const Root = ({ store, history }) => (
<Provider store={store}>
<ConnectedRouter history={history}>
<Switch>
<Route path="/" component={App} />
</Switch>
</ConnectedRouter>
</Provider>
);
我在这里测试了解决方案:https://hackernoon.com/animated-page-transitions-with-react-router-4-reacttransitiongroup-and-animated-1ca17bd97a1a - 但它不起作用。有人能指出我正确的方向吗?
更新
我试过这样,但回调没有被调用。所以我最终得到了 dom 中的页面。
export const App = ({ location }) => {
console.log(location);
return (
<div className="app-container">
<main className="app-container__content">
<ScrollToTop />
<TransitionGroup>
<Switch key={location.pathname} location={location}>
<Route exact path="/projects/:slug" component={ProjectPage} />
<Route exact path="/" component={StartPage} />
</Switch>
</TransitionGroup>
</main>
</div>
);
};
【问题讨论】:
-
如果hackernoon 演示对您不起作用 - 我建议您发布您正在使用的代码,以防教程代码中出现一些小的差异
-
@icc97 他没有使用最新版本的 React 过渡组。 medium.com/@martinhaagensli/…
标签: reactjs react-router react-redux react-transition-group