How to achieve a fade effect page transition between vue-router defined pages (components)?
Vue.js page transition fade effect with vue-router
38.8k views Asked by Kaspi At
2
There are 2 answers
0
Orlandster
On
Plug and Play Solution
There is also a plug and play solution called vue-page-transition which offers you all sort of transitions. (fade, flip, zoom, overlay etc.)
1 - Install the npm package:
yarn add vue-page-transition
2 - register the plugin:
import Vue from 'vue'
import VuePageTransition from 'vue-page-transition'
Vue.use(VuePageTransition)
3 - wrap your router-view with the global animation:
<vue-page-transition name="fade-in-right">
<router-view/>
</vue-page-transition>
Learn more on GitHub: https://github.com/Orlandster/vue-page-transition
Related Questions in TRANSITION
- How to make an animation happen everytime I click on a div that has the animation?
- Script for transition plot in R
- VueJS - Transition-group idea for single-item replacements
- Tailwind transition stop working in React
- Launch an Android Application programatically without an Animation/Transition
- Page transition using next.js and R3F
- CSS Error automatic zoom in background image when transition flex-grow
- Transition for Gradient Background
- transition animations for subviews in SwiftUI
- Children view controllers must have a common parent view controller in swift
- How to handle states and transitions in nestjs?
- How to remove background of a view with different Transition?
- Change Font Size of Text in Navigation
- Nutx 3 layout transitions not working. Why?
- How to add transition using a JS file
Related Questions in FADE
- Is there a fade in and out simpler, less complicated solution?
- How do I make the images fade in and out, not just appearing once, in a carousel?
- How can I create a fixed gradient opacity for text or images in Flutter?
- Fade effect with Swiper.js makes links unclickable. How to solve it?
- Highchart piechart colour fade for smaller slices
- How to draw a line with faded ends?
- CSS overlay effect keeps flickering on mouse over
- Why does my screen fade effect only happen once?
- Smooth transition for sticky navigation on fade in and out
- I want to fade in a navbar as soon as it comes into view and simultaneously fade out another navbar
- How can I make my background image fade in with the same transition as the rest of my webpage using CSS and HTML?
- Fade out text on horizontal scroll
- Images appear then disappear in slideshow gallery after approximately 2 seconds
- Making a fade transition using JPanels
- React and material ui fade effect same for both elements
Related Questions in EFFECT
- Pdf with page cURL effect
- Angular Effects Unit test: RxJs race operator
- How to change the plot background color generated by plot(effect(...)) in grey with white grid in R?
- Angular v17 control flow for loop on select control throwing error with effect
- simulate simplicity mvvm trigger() throw index.html:72 Uncaught RangeError: Maximum call stack size exceeded
- Blinked image when cursor enter in the image
- SwiftUI Rolling Text Animation Freezes with Rapid User Input
- How to correctly use Angular signal effect with arrays?
- Typewriter Effect on a list
- Bg Opacity change on scroll
- how can I add a scroll down panel effect on my squarespace website?
- How to add moving light overly on top of linear progress indicator - Flutter
- CSS Blury background Effect
- Android- How to perform image scaling based on the scroll direction of the NestedScrollView?
- How can I add a glow effect to editor text in a VS Code theme?
Related Questions in VUE-ROUTER
- Pass dynamic object data via nuxt-link to component
- Uncaught TypeError: _projects_js__WEBPACK_IMPORTED_MODULE_2__.default is undefined
- Vue 3 router changing <routing-view/> but not URL
- Vue Router and AWS Amplify
- How to check param route in router
- Vue router with Wordpress
- Route requests as POST on Quasar (Vue3) client application
- Handling a this.$router.replace(href); in vue 2
- How can I conditionally include content without a jarring animation?
- How to efficiently Fetch Dynamic Routes?
- Vue Query get parameters as an array
- Vue prop from optional router param is empty string instead of default value
- My elements will only appear (sometimes) after hot reloading, but not in first load
- Getting blank page while trying to use props in history mode in vue router
- How to get current route in Vue 3 outside of component?
Related Questions in VUE.JS
- Problems with matter.js and i18n in vue.js
- Form Validation not working in custom component Vue
- Authenticating vue app on each route change
- Vue/TailwindCSS - Content is behind Sidebar
- Vue3 Suspense Parent > Child Animation
- Pass dynamic object data via nuxt-link to component
- Failed to resolve import, but the path is valid, and detected as such by VSCode
- how to use less variables in vue components?
- Prevent a webpage from navigating away
- Creating a modal window in product edit page in Shopware6 and saving data to custom table(repository) from a form within the modal window
- How do I fix (or ignore) a TypeScript error that's inside a HTML template?
- Vue.js Checkbox Alignment Issue: Centering Checkboxes Within Table Cells
- How to reset vue product filter?
- Vue display output of two dimensional array
- vue js error when adding bonus items to another item
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Wrap
<router-view></router-view>with<transition name="fade"></transition>and add these styles:Detailed answer
Assuming you have created your application with vue-cli, e.g.:
Install the router:
If you are not developing your app using vue-cli, make sure to add the vue router the standard way:
You can use e.g.: https://unpkg.com/vue-router/dist/vue-router.js
The CLI has created a backbone application for you, which you can add components to.
1) Create page components
In Vue, components (UI elements) can be nested. A page in your app can be made with a regular Vue component that is considered as the root to other components in that page.
Go to
src/and createpages/directory. These page-root components (individual pages) will be put in this directory, while the other components used in the actual pages can be put to the ready-madecomponents/directory.Create two pages in files called
src/pages/Page1.vueandsrc/pages/Page2.vuefor starters. Their content will be (edit page numbers respectively):2) Setup routing
Edit the generated
src/main.jsadd the required imports:Add a global router usage:
Add a router setup:
The last route just redirects the initial path
/to/page1. Edit the app initiation:The whole
src/main.jsexample is at the end of the answer.3) Add a router view
Routing is set up by now, just a place where the page components will be rendered according to the router is missing. This is done by placing
<router-view></router-view>somewhere in the templates, you will want to put it in thesrc/App.vue's<template>tag.The whole
src/App.vueexample is at the end of the answer.4) Add fade transition effect between page components
Wrap the
<router-view></router-view>with a<transition name="fade">element, e.g.:Vue will do the job here: it will create and insert appropriate CSS classes starting with the name specified through-out the effect's duration, e.g.:
.fade-enter-active. Now define the effects in App.vue's section:That's it. If you run the app now, e.g. with
npm run dev, it will automatically display Page 1 with a fade-in effect. If you rewrite the URL to /page2, it will switch the pages with fade-out and fade-in effects.Check out the documentation on routing and transitions for more information.
5) Optional: Add links to pages.
You can add links to particular pages with the
<router-link>component, e.g.:This automatically gives the links a
router-link-activeclass in case they are active, but you can also specify custom classes if you are using e.g. Bootstrap:Files for reference
src/main.js:
src/App.vue:
src/pages/Page1.vue:
src/pages/Page2.vue: