【问题标题】:Transition page content excluding the header and footer不包括页眉和页脚的过渡页面内容
【发布时间】:2021-06-25 23:37:28
【问题描述】:

我一直在尝试使用 framer motion 和 react router 在我的网站上的页面之间添加一些不错的过渡。

这是我的代码:

        <AnimatePresence initial={false} exitBeforeEnter>
            <Switch location={location} key={location.pathname}>
                
                <Route path="/" exact>
                    <LandingPage />
                </Route>

                <PrimaryLayout>     
                    <Route path="/home">
                        <HomePage />
                    </Route>

                    <Route path="/about" >
                        <AboutUs />
                    </Route>

                    <Route path="/test" >
                        <TestPage />
                    </Route>
                </PrimaryLayout>

            </Switch>
        </AnimatePresence>

“PrimaryLayout”只是一个带有标题的布局,着陆页是唯一使用此布局的页面。

登录页面和任何其他页面之间的动画运行顺畅,因为带有标题的布局随着页面内容淡入,但在都使用该布局的页面之间转换是我正在努力解决的问题。

每当我在这些页面之间切换时,带有标题的布局都会动画出来,然后再返回,看起来很奇怪。

对此的任何帮助将不胜感激。

【问题讨论】:

    标签: javascript reactjs react-router react-router-dom framer-motion


    【解决方案1】:

    假设您的页眉和页脚对于所有页面都是相同的,您应该将页眉和页脚移出您的 Page 组件,并移出 &lt;AnimatePresence&gt; 组件。

    <Header />
             <AnimatePresence initial={false} exitBeforeEnter>
                <Switch location={location} key={location.pathname}>
                    {/* Only the main content gets animated. No headers / footers in here. */}
                </Switch>
            </AnimatePresence>
    <Footer />
    

    【讨论】:

    • 是的,但是页眉和页脚会出现在我不想要的目标网页上
    • 然后有条件地渲染 &lt;Header /&gt;&lt;Footer /&gt; 以便它也只显示在您想要的页面上。
    猜你喜欢
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2015-10-22
    • 2015-03-03
    • 2022-01-15
    相关资源
    最近更新 更多