All Projects → posva → vue-router-view-transition

posva / vue-router-view-transition

Licence: other
Properly time out-in transitions with scrollBehavior

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to vue-router-view-transition

Vueg Page Transition Plugin
为Vue应用添加页面间的转场特效( Page level transition plugin for vue-router)
Stars: ✭ 1,023 (+2592.11%)
Mutual labels:  transition, vue-router
friendly-vue-starter
Full featured Vue.js starter project for browser apps
Stars: ✭ 37 (-2.63%)
Mutual labels:  vue-router
vue-seo-friendly-spa-template
Vue.js PWA/SPA template initially scaffolded with vue-cli and configured for SEO. Makes use of prerendering and other techniques/packages in order to achieve a perfect "Lighthouse Score".
Stars: ✭ 41 (+7.89%)
Mutual labels:  vue-router
vue-loopback
A Vue project template with Loopback framework optionally with Vuex, Vue-router, and Auth boilerplaite
Stars: ✭ 52 (+36.84%)
Mutual labels:  vue-router
vue3-docs
vue中文社区,vue3 中文文档
Stars: ✭ 180 (+373.68%)
Mutual labels:  vue-router
mmf-blog-vue2-pwa-ssr
mmf-blog-vue2 ssr(The service side rendering)
Stars: ✭ 65 (+71.05%)
Mutual labels:  vue-router
Laravel-Vue-SPA-template
Template for Single Page Applications built with Laravel and Vue.
Stars: ✭ 22 (-42.11%)
Mutual labels:  vue-router
use-routes
🚩 A router hook for not only react hooks API but also fre
Stars: ✭ 35 (-7.89%)
Mutual labels:  vue-router
dpar
Neural network transition-based dependency parser (in Rust)
Stars: ✭ 41 (+7.89%)
Mutual labels:  transition
megalo-router-patch
在 megalo 中使用 vue-router 的路由写法
Stars: ✭ 15 (-60.53%)
Mutual labels:  vue-router
mall-app-vant
有来商城youlai-mall移动APP端,技术栈:Vant,已计划变更使用uni-app适配Android、IOS端开发。
Stars: ✭ 33 (-13.16%)
Mutual labels:  vue-router
vue3-chat
2021👨‍🎓Vue2/3全家桶 + Koa+Socket+Vant3前后端分离移动端聊天应用。vue+node全栈入门项目
Stars: ✭ 46 (+21.05%)
Mutual labels:  vue-router
vue-jsPlumb
jsPlumb with Vue 2.【WIP】
Stars: ✭ 66 (+73.68%)
Mutual labels:  vue-router
meal-ticket
前端基于webpack+vue+vux,后端基于express+lowdb。有了这些,开发一个项目将会变得很轻松。
Stars: ✭ 19 (-50%)
Mutual labels:  vue-router
vue-boilerplate
Vue boilerplate
Stars: ✭ 28 (-26.32%)
Mutual labels:  vue-router
anim8js
The ultimate animation library for javascript - animate everything!
Stars: ✭ 33 (-13.16%)
Mutual labels:  transition
FiniteStateMachine
This project is a finite state machine designed to be used in games.
Stars: ✭ 45 (+18.42%)
Mutual labels:  transition
vue-admin-work
🎉🎉🚀🚀🚀🚀vue-admin-work是一个中后台系统管理方案。使用 vue2.x 及周边全家桶工具开发而来。支持多种功能,不同角色权限🚀🚀🚀🎉🎉
Stars: ✭ 74 (+94.74%)
Mutual labels:  vue-router
vue-typescript-admin
Vue typescript 开发的基础模板,多页面支持,基础整合完毕。
Stars: ✭ 26 (-31.58%)
Mutual labels:  vue-router
utransition
A tiny (~2KB) library providing you an easy way to manage time-based transitions
Stars: ✭ 22 (-42.11%)
Mutual labels:  transition

vue-router-view-transition Build Status npm package thanks

A transition wrapper for router-view that is compatible with scrollBehavior

Installation

npm install vue-router-view-transition
# or
yarn add vue-router-view-transition

Usage

This library exports one component and one function. You need to use both:

First, you can either globally install the component RouterViewTransition:

import { RouterViewTransition } from 'vue-router-view-transition'

Vue.component('RouterViewTransition', RouterViewTransition)

or import it locally in any Vue component:

import { RouterViewTransition } from 'vue-router-view-transition'

export default {
  components: { RouterViewTransition },
}

Then you should replace your router-view with this router-view-transition:

<router-view-transition transition="fade" mode="out-in" />

Here the transition prop refers to the name of the transition (prop named name for the transition component) while the mode is exactly the same as the prop with the same name in the transition component.

Then you must import the waitForTransition function and wrap your scrollBehavior function:

// probably your router.js file
const router = new Router({
  mode: 'history',
  routes: [
    // your routes
  ],
  scrollBehavior: waitForTransition((to, from, savedPosition) => {
    // this code will get executed only once the transition wrapping router-view is finished
    // this ensures
    if (savedPosition) {
      return savedPosition
    } else {
      // this ensures we go to the top of the page when navigating to a new page
      return { x: 0, y: 0 }
    }
  }),
})

Note: You may also want to enable manual scroll restoration:

history.scrollRestoration = 'manual'

Related

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].