【发布时间】:2021-03-25 20:46:45
【问题描述】:
我使用 Next.js、React、TypeScript 和 Framer Motion。
我不使用反应路由器。
我想在页面之间进行转换。
当我更改页面(在_app.tsx 中)时,我发现了如何从右到左转换。
但是,如果我使用向右箭头和向左箭头的链接,这是相同的过渡。
我想用右箭头从右到左转换,用左箭头从左到右转换。
我的_app.tsx:
import '../public/css/style.scss';
import { animate, AnimateSharedLayout, motion } from 'framer-motion';
import { useRouter } from "next/router";
import App from "next/app";
//import Strategie from './strategie'
export default class MyApp extends App {
render(){
const { Component, pageProps } = this.props;
const { router } = this.props;
// const { router } = this.props;
return <>
<motion.div key={router.route} initial="pageInitial" animate="pageAnimate" exit="pageExit" variants={{
pageInitial: {
opacity: 0,
x: "100%",
},
pageAnimate: {
opacity: 1,
x: 0,
transition: {
ease: "easeIn",
duration: 0.5,
}
},
pageExit: {
// filter: `invert()`,
opacity: 0,
}
}}>
<Component {...pageProps} />
</motion.div>
</>
}
}
我的页面有 2 个箭头(我有几个这样的页面):
import React from "react";
import HomePageBlock, {IdHomePageBlockProps} from '../components/common/home pages/homePage-block';
import ButtonStartProject from "../components/buttons/button-startProject";
import Link from "next/link";
import Sidebar from "../components/common/sidebar/sidebar";
interface IdHomePageSingularityProps {
title?: string;
}
interface IdHomePageSingularityState{
homePageInfos: IdHomePageBlockProps[]
}
export default class HomePageSingularity extends React.Component<IdHomePageSingularityProps, IdHomePageSingularityState>{
constructor(props){
super(props);
this.state = {
homePageInfos: [
{
title: <>Révélons <br/> ta singularité</>,
subTitle: "notre expertise",
description: <>Nombreux sont les projets qui émergent aujourd'hui, alors comment se démarquer quand tu as un projet bienveillant sans perdre en efficacité ? <br/> Chez Ben&Jo nous concevons des identités visuelles basés sur une stratégie cohérente. Nous inventerons pour ton projet un univers visuel unique et impactant !</>,
img: { url : "/img/home-pages/singularity.svg"},
buttonDiscover: <>
<Link href="/brandingIndex">
<a className="buttonDiscover" >DECOUVRE NOTRE SAVOIR FAIRE !</a>
</Link></>,
buttonStartProject: <><ButtonStartProject /></>,
imgFingersBox: { url : "/img/home-pages/fingersBox.svg"},
arrowRight: <>
<Link href="/homePageSucces">
<img src="/img/home-pages/arrowRight.svg" />
</Link></>,
arrowLeft: <>
<Link href="/homePageStrategie">
<img src="/img/home-pages/arrowLeft.svg" />
</Link>
</>,
}
]
}
}
render(){
const { homePageInfos } = this.state;
return <>
<div className="home__singularity">
<div><Sidebar /></div>
{ homePageInfos && homePageInfos.map((item, index) => {
return <HomePageBlock key={"home__singularity-block_" + index }
{...item} className="home__singularity-block"/>
})
}
</div>
</>
}
}
我构建组件的页面:
import React from 'react';
import FingersBox from './fingersBox';
export interface IdHomePageBlockProps {
title?: {};
subTitle?: string;
description?: {};
img?: {url: string, alt?: string};
buttonDiscover?: {};
buttonStartProject?: {};
arrowRight?: {};
arrowLeft?: {};
className?: string;
imgFingersBox?: {url: string, alt?: string};
}
export interface IdHomePageBlockState{
}
export default class HomePageBlock extends React.Component<IdHomePageBlockProps, IdHomePageBlockState>{
render(){
const { title, subTitle, description, img, buttonDiscover, buttonStartProject, arrowRight, arrowLeft, className } = this.props;
return <>
<div className={className + ' homePage-block'}>
<header>
<div className="homePage-block__imageFingers-box"><FingersBox /></div>
<div className="homePage-block__subTitle">{subTitle}</div>
<div className="homePage-block__buttonStartProject">{buttonStartProject}</div>
</header>
<body>
<main>
<div className="homePage-block__title">{title}</div>
<div className="homePage-block__description">{description}</div>
<div className="homePage-block__buttonDiscover">{buttonDiscover}</div>
</main>
<aside>
<div className="homePage-block__image-box">
<img src={img.url} alt={img.alt} />
</div>
</aside>
</body>
<footer>
<div className="homePage-block__arrowLeft">{arrowLeft}</div>
<div className="homePage-block__arrowRight">{arrowRight}</div>
</footer>
</div>
</>
}
}
如您所见,没有按钮,只有链接。
【问题讨论】:
-
感谢您的指正,您有办法解决我的问题吗?
标签: reactjs next.js framer-motion