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 best solutions below
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 place group of markers with transition effect?
- Markov chain: join states in Transition Matrix
- IOS: Transition with modal ViewContorller
- CSS: Skew a buttons border, not the text
- CSS Transition in a nested list
- crossfilter | animate through date range
- Applying popbio "projection.matrix" to multiple fertilities and generate list of matrices
- CSS background-color transition not working in specific browsers (desktop + mobile)
- Pseudo elements transition on IE 11 ignores padding
- Transition partition arcs back to original angles
- CSS transition width/position with long duration issue
- Fragment Transactions with transition - Unique transitionNames are required
- iOS: Going back to previous screen always waits until scroll finishes
- Page transitions from https://www.dropbox.com/guide using JQuery
- Unity C# Animator Transitions
Related Questions in FADE
- Fading in and out with Click
- VB.NET Fading out button properly
- How to evenly time fading transitions?
- I want to fade the whole background on focus
- Fade in new background image images on scroll
- Navigation transition, overriding negations
- Sequence Action With EnumerateChildNodeWithName
- jQuery: Refreshing DIV before fading
- How to fade out audio/music between scenes?
- Vue.js page transition fade effect with vue-router
- Toggle, fade in, fade out. Open slider and change content
- Fade out last few lines of a TextView
- position:absolute element messes up fading of another
- Android Textview Truncate
- setInterval to fade in then fade out pure javascript no jquery or css
Related Questions in EFFECT
- CSS: Skew a buttons border, not the text
- Fade in new background image images on scroll
- Keep hover effect activated to smart phones & tablets
- iphone - custom UIAlertView block effect
- Vue.js page transition fade effect with vue-router
- Link in typed.js text
- Resize Responsive image without stretch + zoom effect on image link
- Average Effectiveness of Variables in Binary Logistic Model
- When scroll wordpress header change
- Shadow effect and blurry text
- Create "no more scroll possible" effect for HorizontalScrollView
- MVC dynamic menu
- Slider two div at the same time left to right
- How can I do a "close effect" in an image?
- Android divide activity into two parts
Related Questions in VUE-ROUTER
- Call from component to parent with $emit
- Best way to implement history function inside Vue.js modal
- <transition> can only be used on a single element
- Vue.js page transition fade effect with vue-router
- Change component and update data (ajax) when vue-router item is clicked
- VueJS Adding data from query parameters
- Control modals using vue router
- Vue router shows lazy-loaded route components only once
- How to remove the hash # when the base URL is not root?
- Pass global JSON to Vue app from flask webserver
- Vue-router reload components
- Separating script, style and template in Vue.js and Webpack
- Click on link changes the url but not the content/data on page
- Vue.js router init works with router.map not with the Router constructor
- How can I re initialize same components in different routes
Related Questions in VUE.JS
- jqBootstrapValidation() is not a function
- In Vue.js, change value of specific attribute for all items in a data array
- Vue.js - How to handle all elements with the same selector?
- How can I use Elixir + Vueify?
- Bind function on newly created element
- Vue.js Passing data to content scope
- Updating the DOM with change in an object (vue.js) - binding not working?
- websocket + vuejs: screen flickering, visible mustache code
- Vue.js nested v-repeat: How to access parent $index inside child?
- VueJS - trouble understanding .$set and .$add
- Difference between two similar functions, why is one working and the other not
- Display unescaped HTML in Vue.js
- Mouseover or hover vue.js
- vuejs: Trying to focus the input using v-el directive
- Vue.js component issue
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)
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?
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: