Frameer Motion Animate Presence不适用于新NextJS应用程序路由器的拦截路由

xhv8bpkk  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(85)

我试图创建一个使用拦截路由的模态,如NextJS文档中的example所示。我正在使用成帧器运动来实现模态动画,但Animate Presence在这种情况下不起作用。
app/(features)/@loginModal/(.)login/page.tsx中的page.tsx文件

import Modal from "@General/Modal";
import Login from "@Auth/Login";

export default function NavbarLogin() {
    return (
        <Modal>
            <Login />
        </Modal>
    );
}

app/(features)/layout.tsx中的layout.tsx文件

"use client";

import { AnimatePresence } from "framer-motion";
import Navbar from "@Navbar/Navbar";
import Guard from "@Auth/Guard";

export default function MainLayout({
    children,
    loginModal,
}: {
    children: React.ReactNode;
    loginModal: React.ReactNode;
}) {
    console.log(loginModal);
    return (
        <Guard>
            <main>
                <Navbar />
                <div className="pt-20">
                    {children}
                    <AnimatePresence>{loginModal}</AnimatePresence>
                </div>
            </main>
        </Guard>
    );
}

我尝试将AnimatePresence标签更改为不同的位置,如app/layout.tsxapp/(auth)/layout.tsxapp/(auth)/login/page.tsx等。但它没有工作。
编辑:在github https://github.com/framer/motion/issues/1850https://github.com/vercel/next.js/issues/49279上发现了这个问题,但是在当前版本中没有提到的解决方法。有人知道如何在最新版本中修复这个问题吗?

3j86kqsm

3j86kqsm1#

当使用动画呈现时,帧器组件需要具有入口、出口和关键 prop 。

<AnimatePresence>
                {open && (
                    <motion.div
                        key='box'
                        initial={{ opacity: 0, y: '-100%' }}
                        exit={{ opacity: 0, y: '-100%' }}
                        animate={{ opacity: 1, y: 0 }}
                        transition={{ duration: 0.5, ease: 'easeOut' }}
                        className='flex flex-col items-center justify-center gap-8 md:hidden bg-primary'
                    >
                        ...component related work here
                    </motion.div>
                )}
            </AnimatePresence>

key prop 很重要,因为Framer需要它来确定要将动画添加到哪个组件。

相关问题