Reputation: 43
I am trying to add page transitions to my Nextjs app. What should I do to add that?
Upvotes: 4
Views: 4336
Reputation: 3611
You can install the dependency react-transition-group
$ npm install react-transition-group
create a transition_sample.js
or transition_sample.tsx
component in the component folder
Next, import the transition_sample.js
or transition_sample.tsx
component to your layouts/MainLayout
or _app.js
or _app.tsx
if you're doing this in the _app.js/_app.tsx
be sure to replace children with <Component {...pageProps} />
Import useRouter
from next//router
and pass the pathname to location props
All done then use the MainLayout
in your pages
and to use the layout wrap your pages with MainLayout
.
Upvotes: 1