-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Transition effects when route slug changes #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @jsiebach
to get a fresh component invoking all transition hooks and effects..! |
Closing since this is already fixed 😄 . |
The solution no longer works with vue-router 2.x, |
@myst729 Using the key attribute with a computed property should work |
@posva Yep, this just works for me: <transition name="view" mode="out-in" appear>
<router-view :key="$route.fullPath"></router-view>
</transition> |
Here is a quick tutorial for that I wrote! |
@myst729 Is it also possible to do this for only a specific route? I have a transition on all my pages like: /blog, /about-us etc. I want the transition to also happen on /blog/:slug but not on /service/:slug |
Nevermind i fixed it with a computed route like this: |
The vue-router component can have a 'key' property which means it's easier to configure transitions between routes with slugs. With this change in a layout template you can use ```html <nuxt :routerViewKey="routerViewKey" /> ``` And the following for example ```js computed: { routerViewKey () { if (this.$route.name === 'service') { return this.$route.name } else { return this.$route.fullPath } } } ``` This would implement the functionality that @myst729 mentioned here vuejs/vue-router#474 for vue-router - some routes can just switch, but some you may want to transition as though it's a complete new page to an end-user This is a possible resolution to issue raised here nuxt#1021
@andre-dw maybe just using an if in key prop is better. Computed seems overload |
Uh oh!
There was an error while loading. Please reload this page.
Edit: as I finally got this working, I realized it was very similar to vuejs/vuex-router-sync#3 . The ability to call actions within router hooks ended up being what solved it. So I guess this may be fixed when router hooks are simplified. But the ability to put a transition on a watched variable still makes sense, so I'm posting this anyway.
TL;DR: It would be a feature to allow a transition when data changes. IE if you have
<span>Name: {{name}}</span>
andname
is changed, it would fade-out and then fade-in.I've used
<router-view transition="fade" transition-mode="in-out">
to provide a fade-out, fade-in effect when changing from one route to another. Now I'm having trouble doing the same thing where the route slug changes, but the component and the route are remaining the same.I've got a
Page
component that uses avuex
getter to return the content of the current page based on the URL. The route is available in thestate
thanks tovuex-router-sync
:Then I am able to access the current page via this getter in my
Page.vue
component:So when the URL updates, the page content immediately updates. I cannot seem to find a way to use a fade-out, fade-in effect on this change.
<router-view>
transition is not triggered:is="component"
transitionI tried a couple of things, like placing a
setTimeout
in theroute.data()
function that delayednext()
by some time:Then I hid the component during
$routeDataLoading
. I got a proper fade out fade in effect, however thepage
variable updated immediately, so the page content updated before thefade-out
even began.What I finally did to get it going was a hack to allow actions within router hooks:
Since my fade is .15s, this faded out the div during
$routeDataLoading
, and then faded it back perfectly .15s later when the timeout finished.The text was updated successfully, but these errors were encountered: